[rspec-users] RSpec 2 view example: render_template
Michael Schuerig
michael at schuerig.de
Sun Jun 20 10:38:42 EDT 2010
On Sunday 20 June 2010, David Chelimsky wrote:
> On Jun 20, 2010, at 8:03 AM, David Chelimsky wrote:
> > On Jun 20, 2010, at 7:30 AM, Michael Schuerig wrote:
> >> On http://github.com/rspec/rspec-rails under "View specs" there's
> >> an example
> >>
> >> describe "events/index.html.erb" do
> >> it "renders _event partial for each event" do
> >>
> >> assign(:events, [stub_model(Event), stub_model(Event)])
> >> render
> >> view.should render_template(:partial => "_event", :count => 2)
> >>
> >> end
> >> end
> >>
> >> Is this indeed correct? From the outset, it looks wrong because it
> >> sets an expectation (view.should ...) after the call to render.
>
> Yeah - I see that this is confusing. Maybe we should change that to
> view.should have_rendered("..."). If so, we should also change
> response.should render_tempate("...") and response.should
> redirect_to("....") in controller specs.
That behavior would be more useful, in my opinion. In view and
controller specs I like to put the render or get/post/... at the end of
a begin block and then do the checks in the actual examples.
Michael
--
Michael Schuerig
mailto:michael at schuerig.de
http://www.schuerig.de/michael/
More information about the rspec-users
mailing list