[rspec-users] Documentation about the returns method
dchelimsky at gmail.com
Wed Jan 14 17:42:59 EST 2009
On Wed, Jan 14, 2009 at 3:53 PM, Fernando Perez <lists at ruby-forum.com> wrote:
> Fernando Perez wrote:
>> From the railscasts website source code, in the episodes_controller_spec
>> I read:
>> it "index action with search should search published episodes" do
>> get :index, :search => 'foo'
>> Here are my questions:
>> - What does the returns(Episode.all) mean?
This calls Episode.all one time and stores the result. When Episode
receives :search_publishe with 'foo', that's what it returns. Make
>> - Is it stubbing what the search_published method returns?
>> - Is it useful to add the returns(Episode.all) method call here?
If you don't, nothing will be returned. If the application code relies
on the return value, then it is definitely useful - necessary, in
>> - Whats the difference with and_return(Episode.all)?
No semantic difference - different library (see below).
>> - Shouldn't we only test for:
No - the returns statement is not part of the expectation - it's the
value to return when search_published is received.
> I also forgot to add:
> What's the difference between expects and should_receive? I can get my
> head around it.
Two different mocking libraries:
mocha (used in the screen cast):
> Posted via http://www.ruby-forum.com/.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users