I am new to mock objects, and I am trying to learn how to use them in RSpec. Can someone please post an example (a hello RSpec Mock object world type example), or a link (or any other reference) on how to use the RSpec mock object API?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s an example of a simple mock I did for a controller test in a rails application:
In this case, I’m mocking the Page & PageType models (Objects) as well as stubbing out a few of the methods I call.
This gives me the ability to run a tests like this:
I know this answer is more rails specific, but I hope it helps you out a little.
Edit
Ok, so here is a hello world example…
Given the following script (hello.rb):
We can create the following spec (hello_spec.rb):