Thanks, first, to everyone who's asked and answered questions on this list, and to the creators of RSpec - it is all very helpful. I've searched the mailing list, and had a couple 2hr googling sessions that didn't help me find an answer.
<br><br>I've run into a problem getting my first non-trivial view spec to run. I get an error when trying to generate a link_to() to another resource. Here is an overview of the situation, then the code:<br><br><ul>
<li>I'm using a restful design</li><li>I'm using nested (multiply nested) resources</li><li>I am trying to test a <span style="font-style: italic;">show<span style="font-style: italic;">.rhtml</span></span> view, that includes links (link_to) to resources managed by another controller
</li><li>The use_case model has a many-to-may <span style="font-style: italic;">through</span> relationship with actors, and I'm displaying links to the associated actors on the use_case page<br></li><li>I can't get the links to generate when running rspec (but it works great in the app)
<br></li><li>I am in the early stages of the project, and want to move forward BDD, but I have some existing code that I need to test before I can start moving forward again.<br></li></ul>My theories: I need to stub the controller (for the other resource), or I need to stub something else.
<br><br>Here's the command I'm running to drive RSpec<br>
<br>
<span style="font-family: courier new,monospace;">ruby script/spec -f s spec/views</span><br style="font-family: courier new,monospace;"><br>Here's the error that I get<br><br><span style="font-family: courier new,monospace;">
1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ActionView::TemplateError in 'UseCase showing a use case should display the use case identifier'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace; font-weight: bold;">actor_url failed to generate from {:customer_id=>"1", :controller=>"actors", :action=>"show", :project_id=>"1"}, expecte
</span><br style="font-family: courier new,monospace; font-weight: bold;"><span style="font-family: courier new,monospace; font-weight: bold;">d: {:controller=>"actors", :action=>"show"}, diff: {:customer_id=>"1", :project_id=>"1"}
</span><br style="font-family: courier new,monospace; font-weight: bold;"><span style="font-family: courier new,monospace; font-weight: bold;">On line #22 of app/views/use_cases/show.rhtml</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 19: <ul></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
20: <% @primary_actors.each do |a| %></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 21: <li></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace; font-weight: bold;"> 22: <%= link_to(<a href="http://a.name">a.name</a>,actor_path(@customer,@project),{:class=>"show",:title=>"Show actor details"}) -%>
</span><br style="font-family: courier new,monospace; font-weight: bold;"><span style="font-family: courier new,monospace;"> 23: <%= link_to("Remove assignment",participation_path(@customer,@project,@use_case.participations.find_by
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">_actor_id(a)),{:class=>"delete",:title=>"Remove the assignment of this actor to this use case", :confirm => 'Are you sur
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">e you want to remove this assignment?', :method => :delete})-%></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 24: </li></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 25: <% end %></span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/routing.rb:1273:in `raise_named_route_error'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/routing.rb:1245:in `generate'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:104:in `rewrite_path'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:69:in `rewrite'
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:522:in `url_for'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:27:in `url_for'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
(eval):19:in `actor_path'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/app/views/use_cases/show.rhtml:22:in `_run_rhtml_47app47views47use_cases47show46rhtml'
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/app/views/use_cases/show.rhtml:20:in `_run_rhtml_47app47views47use_cases47show46rhtml'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:326:in `compile_and_render_template'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:301:in `render_template'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_view/base.rb:260:in `render_file'
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:806:in `render_file'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/base.rb:741:in `render_with_no_layout'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
#{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/layout.rb:256:in `render_without_benchmark'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> c:/dev/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #{RAILS_ROOT}/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:50:in `render'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
C:/dev/svn/sherpa/vendor/plugins/rspec_on_rails/lib/spec/rails/dsl/behaviour/view.rb:55:in `render'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> spec/views/use_cases/show_view_spec.rb:40
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:17:in `proc'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/composite_proc_builder.rb:12:in `proc'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/example.rb:71:in `before_example'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/example.rb:25:in `run'
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> c:/dev/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/example.rb:24:in `run'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:81:in `run'
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/dsl/behaviour.rb:75:in `run'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:58:in `run_behaviours'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:57:in `run_behaviours'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in `run'
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> C:/dev/svn/sherpa/vendor/plugins/rspec/lib/spec/runner/command_line.rb:17:in `run'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> script/spec:4</span><br><br>Here's part of my routes.rb, showing the nested resources<br><br><span style="font-family: courier new,monospace;"> map.resources :customers do |customers|
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">
customers.resources :projects</span><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> do |projects|</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;"> projects.resources :actors<br> projects.resources :use_cases<br></span><br><br>Here's some of the stubbing that I am using to set up the spec<br><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> @customer = mock_model(Customer,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> :id => 1,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> :to_param => "1"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> @project = mock_model(Project,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
:id => 1, </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> :customer_id => 1,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
:to_param => "1"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br>I've also stubbed objects to create the following :assigns
<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> assigns[:customer] = @customer</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
assigns[:project] = @project </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> assigns[:use_case] = @use_case</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> assigns[:primary_actors] = @primary_actors</span><br><br>I suspect that there is something else that needs to be stubbed - actors controller, maybe? I really don't know. If anyone can point me in the right direction, or tell me where in the error message to dig deeper, that would be awesome.
<br><br>If I left out any important information, please let me know! And a huge thanks in advance to anyone who can help me out, or explain why this isn't supported, or point me towards any docs or articles that address this issue (because I will have it a zillion times, as almost all views in my app display content and links from more than one model).
<br><br>Scott<br><br>-- <br>Scott Sehlhorst, President Tyner Blain LLC<br><a href="http://tynerblain.com/blog">http://tynerblain.com/blog</a><br><a href="http://tynerblain.com/nexus">http://tynerblain.com/nexus</a>