<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.16.1">
</HEAD>
<BODY>
Hi everyone,<BR>
<BR>
I am relatively new to rspec and I am running into a wall in testing my views. I have a RESTful resource Contracts with a nested resource of Line_items.<BR>
<BR>
I am trying to figure out how to test the &quot;edit&quot; form of the Line_items. What complicates this is the nested routing and how to account for it, and that there is a partial form (_form.haml) that both the edit.haml and new.haml views use (app/views/line_items).<BR>
<BR>
My spec keeps failing and it seems to be from a routing issue. I'm pretty sure template.expect_render/template.stub_render should be in there somewhere, but that just generates more errors.<BR>
<BR>
I am running edge rails and edge rspec. My other spec's are working fine.<BR>
<BR>
See the output from running the spec and the associated files below (edit.haml_spec.rb, edit.haml, _form.haml)<BR>
<BR>
Thanks for your help,<BR>
Troy<BR>
<BR>
########&nbsp;&nbsp;&nbsp;&nbsp; Output from running edit.haml_spec.r&nbsp;&nbsp;&nbsp;&nbsp; ########<BR>
<BR>
F<BR>
<BR>
1)<BR>
ActionView::TemplateError in '/line_items/edit.haml should render edit form'<BR>
contract_line_item_url failed to generate from {:contract_id=&gt;&quot;1&quot;, :action=&gt;&quot;show&quot;, :controller=&gt;&quot;line_items&quot;}, expected: {:action=&gt;&quot;show&quot;, :controller=&gt;&quot;line_items&quot;}, diff: {:contract_id=&gt;&quot;1&quot;}<BR>
On line #6 of app/views/line_items/edit.haml<BR>
<BR>
&nbsp;&nbsp;&nbsp; 3: <BR>
&nbsp;&nbsp;&nbsp; 4: #section1<BR>
&nbsp;&nbsp;&nbsp; 5:&nbsp;&nbsp; = error_messages_for :line_item<BR>
&nbsp;&nbsp;&nbsp; 6:&nbsp;&nbsp; - form_for(:line_item, :url =&gt; contract_line_item_path(@contract.id), :html =&gt; { :method =&gt; :put }) do |f|<BR>
&nbsp;&nbsp;&nbsp; 7:&nbsp;&nbsp;&nbsp;&nbsp; = render :partial =&gt; &quot;form&quot;, :locals =&gt; { :f =&gt; f } <BR>
&nbsp;&nbsp;&nbsp; 8: <BR>
&nbsp;&nbsp;&nbsp; 9:&nbsp;&nbsp;&nbsp;&nbsp; %p<BR>
<BR>
&nbsp;&nbsp;&nbsp; app/views/line_items/edit.haml:6<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/routing.rb:1406:in `raise_named_route_error'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/routing.rb:1370:in `generate'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:124:in `rewrite_path'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:103:in `rewrite_url'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/url_rewriter.rb:81:in `rewrite'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/base.rb:605:in `url_for'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:71:in `send'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_view/helpers/url_helper.rb:71:in `url_for'<BR>
&nbsp;&nbsp;&nbsp; (eval):17:in `contract_line_item_path'<BR>
&nbsp;&nbsp;&nbsp; (eval):15:in `_render_haml_1'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/stable/lib/haml/engine.rb:435:in `send'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/stable/lib/haml/engine.rb:435:in `compile'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/stable/lib/haml/engine.rb:186:in `to_html'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/stable/lib/haml/template.rb:69:in `render'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_view/base.rb:529:in `delegate_render'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_view/base.rb:351:in `render_template_old'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/stable/lib/haml/template.rb:96:in `render_template'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_view/base.rb:303:in `render_file'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/base.rb:1079:in `render_for_file'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/base.rb:831:in `render_with_no_layout'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/layout.rb:269:in `render_without_benchmark'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'<BR>
&nbsp;&nbsp;&nbsp; /usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'<BR>
&nbsp;&nbsp;&nbsp; vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec_on_rails/lib/spec/rails/example/behaviour/view_example.rb:129:in `send'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec_on_rails/lib/spec/rails/example/behaviour/view_example.rb:129:in `render'<BR>
&nbsp;&nbsp;&nbsp; spec/views/line_items/edit.haml_spec.rb:57<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_methods.rb:14:in `instance_eval'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_methods.rb:14:in `run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_runner.rb:57:in `run_example'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_runner.rb:23:in `run'<BR>
&nbsp;&nbsp;&nbsp; /usr/local/lib/ruby/1.8/timeout.rb:48:in `timeout'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_runner.rb:21:in `run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_suite.rb:28:in `rspec_run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_suite.rb:24:in `each'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/example/example_suite.rb:24:in `rspec_run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/extensions/test/unit/example_suite.rb:7:in `run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:22:in `run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in `each'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/runner/behaviour_runner.rb:21:in `run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/runner/options.rb:77:in `run_examples'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/lib/spec/runner/command_line.rb:19:in `run'<BR>
&nbsp;&nbsp;&nbsp; vendor/plugins/rspec/bin/spec:3<BR>
<BR>
Finished in 0.081986 seconds<BR>
<BR>
1 example, 1 failure<BR>
<BR>
<BR>
<BR>
########&nbsp;&nbsp;&nbsp;&nbsp; edit.haml_spec.rb&nbsp;&nbsp;&nbsp;&nbsp; ########<BR>
require File.dirname(__FILE__) + '/../../spec_helper'<BR>
<BR>
describe &quot;/line_items/edit.haml&quot; do<BR>
&nbsp; include LineItemsHelper<BR>
&nbsp; <BR>
&nbsp; before do<BR>
&nbsp;&nbsp;&nbsp; @contract = mock_model(Contract)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:id).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:sdc_ref).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:description).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:sales_rep_id).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:office_id).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:account_id).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:cust_po_num).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:payment_terms).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:hp3000).and_return(false)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:revenue).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:annual_hw_rev).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:annual_sw_rev).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:annual_ce_rev).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:annual_sa_rev).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:annual_dr_rev).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:start_date).and_return(Date.today)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:end_date).and_return(Date.today)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:multiyr_end).and_return(Date.today)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:expired).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:hw_support_level_id).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:sw_support_level_id).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:updates).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:ce_days).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:sa_days).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:discount_pref_hw).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:discount_pref_sw).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:discount_prepay).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:discount_multiyear).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:discount_ce_day).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:discount_sa_day).and_return(&quot;1.5&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:primary_office).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @contract.stub!(:replacement_sdc_ref).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; assigns[:contract] = @contract<BR>
&nbsp;&nbsp;&nbsp; <BR>
&nbsp;&nbsp;&nbsp; @line_item = mock_model(LineItem)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:contract_id).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:support_type).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:product_num).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:serial_num).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:description).and_return(&quot;MyString&quot;)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:begins).and_return(Date.today)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:ends).and_return(Date.today)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:qty).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; @line_item.stub!(:list_price).and_return(&quot;1&quot;)<BR>
&nbsp;&nbsp;&nbsp; assigns[:line_item] = @line_item<BR>
&nbsp; end<BR>
<BR>
&nbsp; it &quot;should render edit form&quot; do<BR>
&nbsp;&nbsp;&nbsp; <BR>
&nbsp;&nbsp;&nbsp; render &quot;line_items/edit.haml&quot;<BR>
&nbsp;&nbsp;&nbsp; <BR>
&nbsp;&nbsp;&nbsp; response.should have_tag(&quot;form[action=#{contract_line_item_path(@contract.id,@line_item.id)}][method=post]&quot;) do<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; with_tag('input#line_item_support_type[name=?]', &quot;line_item[support_type]&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; with_tag('input#line_item_product_num[name=?]', &quot;line_item[product_num]&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; with_tag('input#line_item_serial_num[name=?]', &quot;line_item[serial_num]&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; with_tag('input#line_item_description[name=?]', &quot;line_item[description]&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; with_tag('input#line_item_qty[name=?]', &quot;line_item[qty]&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; with_tag('input#line_item_list_price[name=?]', &quot;line_item[list_price]&quot;)<BR>
&nbsp;&nbsp;&nbsp; end<BR>
&nbsp; end<BR>
end<BR>
<BR>
<BR>
<BR>
########&nbsp;&nbsp;&nbsp;&nbsp; edit.haml&nbsp;&nbsp;&nbsp;&nbsp; ########<BR>
- content_for :subtitle do<BR>
&nbsp; Edit Line Item<BR>
<BR>
#section1<BR>
&nbsp; = error_messages_for :line_item<BR>
&nbsp; - form_for(:line_item, :url =&gt; contract_line_item_path(@contract.id), :html =&gt; { :method =&gt; :put }) do |f|<BR>
&nbsp;&nbsp;&nbsp; = render :partial =&gt; &quot;form&quot;, :locals =&gt; { :f =&gt; f } <BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp; = submit_tag &quot;Update&quot;<BR>
<BR>
#section2<BR>
&nbsp; = link_to('Show', contract_path(@contract)) + ' | ' + link_to('Back', contracts_path)<BR>
<BR>
<BR>
########&nbsp;&nbsp;&nbsp;&nbsp; _form.haml&nbsp;&nbsp;&nbsp;&nbsp; ########<BR>
#section1<BR>
&nbsp; #results.boxed<BR>
&nbsp;&nbsp;&nbsp; %h2 Details<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_item_support_type&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :support_type<BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_item_product_num&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Product num<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :product_num<BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_item_serial_num&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Serial num<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :serial_num<BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_item_description&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :description<BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_item_begins&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Begins<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :begins<BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_item_ends&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ends<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :ends<BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_item_qty&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Qty<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :qty<BR>
<BR>
&nbsp;&nbsp;&nbsp; %p<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %label{:for =&gt; &quot;line_list_price&quot;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List Price<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = f.text_field :list_price<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</BODY>
</HTML>