I''m trying to write my first view spec; I''ve done some
controller specs with
integrated views, but thought that isolating the views for some of these
tests might be nice.
So I wrote this:
> describe PlayerContainer, "show" do
>
> PARENT_ID = 12
> CHILD_NAME = ''Child Name''
> PARENT_NAME = ''Parent Name''
>
> before(:each) do
> parent = mock_model(Customer)
> parent.should_receive(:name).and_return(PARENT_NAME)
> parent.should_receive(:id).and_return(PARENT_ID)
> @container = mock_model(PlayerContainer)
> @container.should_receive(:name).and_return(CHILD_NAME)
> @container.should_receive(:parent).and_return(parent)
> @container.should_receive(:parent_id).and_return(PARENT_ID)
> assigns[:container] = @container
> params[:locale] = ''en-US''
> end
>
> it "should display name" do
> @container.should_receive(:note).and_return(nil)
> render "/player_containers/show"
>
> response.should have_tag(''span#name'', CHILD_NAME)
> end
>
> it "should display note, when present"
>
> it "should display empty note, when not present"
>
> end
If I fire up script/server and point the browser at:
http://localhost:3000/0.1/en-US/player_containers/6
It works just fine. However, when I run the spec, I get:
> 1)
> ActionView::TemplateError in ''PlayerContainer show should display
name''
> customer_url failed to generate from {:action=>"show",
:id=>"12",
> :controller=>"customers"}, expected:
{:action=>"show",
> :controller=>"customers"}, diff: {:id=>"12"}
> On line #11 of app/views/player_containers/show.rhtml
>
> 8: <div class="propsheet-row">
> 9: <b><label
for="name">Parent:</label></b>
> 10: <span class="propsheet-value"
id="parent">
> 11: <%= link_to @container.parent.name,
> parent_org_path(@container, :action => ''show'') %>
> 12: </span>
> 13: </div>
> 14:
>
>
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1273:in
> `raise_named_route_error''
>
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1245:in
> `generate''
>
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/url_rewriter.rb:104:in
> `rewrite_path''
>
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/url_rewriter.rb:69:in
> `rewrite''
>
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:522:in
> `url_for''
>
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/url_helper.rb:27:in
> `send''
>
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/url_helper.rb:27:in
> `url_for''
> (eval):19:in `unsafe_customer_path''
> #{RAILS_ROOT}/lib/url_helper_advice.rb:21:in `customer_path''
> #{RAILS_ROOT}/app/helpers/application_helper.rb:19:in
> `parent_org_path''
> #{RAILS_ROOT}/app/views//player_containers/show.rhtml:11:in
> `_run_rhtml_47app47views47player_containers47show46rhtml''
>
My assumption is that I''ve done something wrong in RSpec, but
I''m not
really sure what; the view seems to work, so as far as I can tell the view
and the route are fine, but the test is not. The error seems to imply the
route shouldn''t have an ID, but ... well ... it should, and it does
when I
fire up the page in my browser, so I''m not entirely sure why running an
RSpec view spec should get me a different result on a named route
generation.
Suggestions?
- Geoffrey
--
Geoffrey Wiseman
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/rspec-users/attachments/20071001/3c0723e7/attachment.html