Recently, I felt the urgent need of mocking one of user method which make some API call, as capybara driver throwing connection reset error whenever, the method which trigger the APi call is invoked in a controller action. I mocked the method with below line of code.
This line, will see that when a controller action is called, it should call the refresh_docs_from_loan_path method of User model and return any thing as a string. It solved my problem, So I tried to learn more about mocking and gone through some useful links as below
-> http://rspec.rubyforge.org/rspec/1.2.7/classes/Spec/Mocks.html #provide detailed documentation on mocking
-> http://www.martinfowler.com/articles/mocksArentStubs.html # it tell the difference between mocking and stubing.
In my above example, @user is my mocked object, which I created using factory girl. but we can also create it with mock class itself as below