breaking into the unknown…

mocking with rspec

Leave a comment

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

-> #provide detailed documentation on mocking

-> # 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

mock(name, options={})

Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s