Welcome to the world of mocks and stubs using minitest-rails. We see various helpful gems that help in mocking and stubbing.
Mocks and stubs are not new concepts that have been introduced in minitest. If you want to get detailed understanding about what are mocks and stubs you should read mocks aren’t stubs written by Martin Fowler. To achieve mocking and stubbing in minitest-rails you don’t need to include any separate gem like rspec-mocks in rspec. Let see how to do work with mocks and stubs in minitest then check what are gems available to add extra functionality.
Stubbing a method means, set a pre-defined return value of a method in test-case. Let’s check how to do method stubbing in minitest:
In this example, I stub
foo and check what would be the output of
new_method. As matter of fact it won’t call actual
foo method instead it calls stub
foo method. Now that we have seen how to stub and instance method, let check how to stub on…
View original post 275 more words