I dont get why I should use Mocks in Rspec.
If I write Specs, shouldn’t I write the actual code afterwards so that the tests would pass?
So why use Mocks and replace those actual classes?
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.
I’m not too familiar with RSpec, but generally you use mocks for everything that you don’t want to test.
Mocks are the things that you use to replace anything but the class under test, so that you have this class in complete isolation. Only then it is a real unit test, otherwise you would test the class under test and all depending/called classes as well, which would then be an integration test (which is useful in certain scenarios, but it’s for sure nothing that you would want to have in TDD/BDD…).
Thomas