[rspec-devel] If you set an expectation on something that's already stubbed, should it return the stubbed value?

Pat Maddox pergesu at gmail.com
Sat Sep 13 17:23:07 EDT 2008


On Sat, Sep 13, 2008 at 4:52 PM, Craig Demyanovich
<cdemyanovich at gmail.com> wrote:
> Pat,
>
> In an earlier message, you wrote:
>
> it "should find the book" do
>  Book.should_receive(:find).with("1")
>  get :show, :id => "1"
> end
>
> [snip]
>
> it "should assign the book to the view" do
>  get :show, :id => "1"
>  assigns[:book].should == @mock_book
> end
>
> Now we've got one example that says we should find the proper book, and
> another one that says we should assign it to the view.  And with these
> two, we can be confident everything is set up properly because there'd
> be no way for @mock_book to make it to the view were it not the same
> object returned by Book.find.
>
> Where does @mock_book come from? A before block?

Yes.  I was just showing a snippet of an example since I was lazy and
didn't want to write a whole spec.

Pat


More information about the rspec-devel mailing list