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.<br><br>So I wrote this:<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
describe PlayerContainer, "show" do<br><br> PARENT_ID = 12<br> CHILD_NAME = 'Child Name'<br> PARENT_NAME = 'Parent Name'<br> <br> before(:each) do<br> parent = mock_model(Customer)<br>
parent.should_receive(:name).and_return(PARENT_NAME)<br> parent.should_receive(:id).and_return(PARENT_ID)<br> @container = mock_model(PlayerContainer)<br> @container.should_receive(:name).and_return(CHILD_NAME)<br>
@container.should_receive(:parent).and_return(parent)<br> @container.should_receive(:parent_id).and_return(PARENT_ID)<br> assigns[:container] = @container<br> params[:locale] = 'en-US'<br> end<br><br>
it "should display name" do<br> @container.should_receive(:note).and_return(nil)<br> render "/player_containers/show"<br> <br> response.should have_tag('span#name', CHILD_NAME)<br>
end<br> <br> it "should display note, when present"<br> <br> it "should display empty note, when not present"<br><br>end</blockquote><div><br>If I fire up script/server and point the browser at:<br>
<a href="http://localhost:3000/0.1/en-US/player_containers/6">http://localhost:3000/0.1/en-US/player_containers/6</a><br><br>It works just fine. However, when I run the spec, I get:<br><blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">
1)<br>ActionView::TemplateError in 'PlayerContainer show should display name'<br>customer_url failed to generate from {:action=>"show", :id=>"12", :controller=>"customers"}, expected: {:action=>"show", :controller=>"customers"}, diff: {:id=>"12"}
<br>On line #11 of app/views/player_containers/show.rhtml<br><br> 8: <div class="propsheet-row"><br> 9: <b><label for="name">Parent:</label></b><br> 10: <span class="propsheet-value" id="parent">
<br> 11: <%= link_to @<a href="http://container.parent.name">container.parent.name</a>, parent_org_path(@container, :action => 'show') %><br> 12: </span><br> 13: </div><br>
14: <br><br> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1273:in `raise_named_route_error'<br> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/routing.rb:1245:in `generate'
<br> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/url_rewriter.rb:104:in `rewrite_path'<br> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/url_rewriter.rb:69:in `rewrite'
<br> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:522:in `url_for'<br> /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/url_helper.rb:27:in `send'<br> /usr/lib/ruby/gems/1.8/gems/actionpack-
1.13.3/lib/action_view/helpers/url_helper.rb:27:in `url_for'<br> (eval):19:in `unsafe_customer_path'<br> #{RAILS_ROOT}/lib/url_helper_advice.rb:21:in `customer_path'<br> #{RAILS_ROOT}/app/helpers/application_helper.rb:19:in `parent_org_path'
<br> #{RAILS_ROOT}/app/views//player_containers/show.rhtml:11:in `_run_rhtml_47app47views47player_containers47show46rhtml'<br></blockquote><br> 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.
<br><br>Suggestions?<br></div><br> - Geoffrey<br>-- <br>Geoffrey Wiseman<br>