You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 29, 2024. It is now read-only.
Just having a quick re-read of "The RSpec Book" and it seems that some of the test code that caused me a bit of confusion might not have if a clearer syntax was used.
double(), stub() and mock() are all effectively the same (they all create an instance of a MockClass).
The reason they exist is to indicate the different intent (rather than using double all the time).
Example give in the book was...
describeStatementdoit"logs a message on generate()"docustomer=stub('customer')customer.stub(:name).and_return('Aslak')logger=mock('logger')statement=Statement.new(customer,logger)logger.should_receive(:log).with(/Statement generated for Aslak/)statement.generateendend
We know the stub method should be used on a Stub and the should_receive should be used on a Mock.
Admittedly that has made the existing code become clearer. But I like the idea of code having clear intention through better terminology.