Notes posted by anexiole
RSS feed![Default_avatar_30](https://www.gravatar.com/avatar/f80c5168b92fe9d49b0668cde3bdd57c?size=30&default=http://apidock.com/images/default_avatar_30.png)
stub/stub! will always be followed by '.and_return'
this function will aways be followed by ‘.and_return(…)’ because a stub is typically used for returning values. The required argument given to stub is a method name. When a message to this stubbed method name is received by a class or existing object of the class AND ‘.and_return’ is provided, the stub will return whatever was provided as argument to ‘.and_return’.
For example,
HomeLoan.stub!(interest_rate).and_return(‘5.5%’)
-
this will return 5.5% when a message for interest_rate in a HomeLoan class’s object is received.
HomeLoan.stub!(interest_rate).and_return(‘5.5%’, ‘3%’)
-
this will return 5.5% when a message for interest_rate in a HomeLoan class’s object is received FOR THE FIRST TIME but will return 3% for subsequent calls/messages.