On Mon, Mar 3, 2008 at 11:21 PM, Namrata Tiwari <[EMAIL PROTECTED]> wrote:
> Here is the action -
>
> def list
> @articles = find_city.articles.paginate :all, :page =>
> params[:page] , :order => "live_on DESC", :conditions => { :type_for
> => "blog" }
> end
>
> and the spec -
>
> it "should list all articles 2" do
> articles = mock("articles")
> get :list
Whoa. A couple of posts ago you said the action (get :list) was the
last thing. Now it's not anymore. When dealing with mocks and stubs,
order is very important, which is why I asked you where the action
was. Message expectations (mocks) and stub values MUST be set before
the action.
> controller.should_receive(:find_city).and_return(articles)
The implementation is find_city.articles, so find_city needs to return
something that owns articles.
> controller.should_receive(:articles)
This one is just wrong - it's the return value of find_city that
should receive articles.
> articles.should_receive(:paginate).with(:order => "live_on DESC",
> :conditions => { :type_for => "blog" })
This one is right, but again, needs to happen before the action.
>
> response.should render_template('articles/list')
This one is correct, and in the correct place (after the action).
> end
>
>
> I am stubbing find_city and articles during set up
>
> before_post do
> controller.stub!(:find_city)
Here find_city will not return anything, so it'll blow up on
find_city.articles ....
> controller.stub!(:articles)
> end
>
> Is this right?
Here's what you want: http://pastie.caboo.se/161001
HTH,
David
> --
>
>
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users