0

rspecビューテストに失敗しましたが、コードは機能します-変数が正しく設定されていない可能性がありますが、それが何であるかを理解できません。

スペックに@incident_report(pp @incident_report)の内容を表示すると、FactoryGirlによって作成されたレコードが正しく表示されます。

実際にレンダリングされたコンテンツ(レンダリングされたプット)を表示すると、FactoryGirlで作成したレコードの値が表示されます...

ただし、「rendered.should contains(work_order)」仕様は次の場合に失敗します。

1) incident_reports/show.html displays the work order number on the incident
   Failure/Error: rendered.should contain(work_order)
     expected the following element's content to include "54785":

データは表示されず、HTMLテンプレートのみが表示されます


spec / views / Incident_report/show.html.haml_spec.rbコード

require 'spec_helper'

describe "incident_reports/show.html" do
  before(:each) do
    @incident_report = Factory(:incident_report)
  end

  it "displays the work order number on the incident" do
    work_order = @incident_report.work_order
    pp @incident_report    #displays an incident_report, id => 1
    assign(:incident_report, @incident_report)
    render 
    puts rendered  #this DOES have the content from @incident_report
    rendered.should contain("Work Order:")
    rendered.should contain(work_order)
    end
  end

show.html.hamlコード

%h1 Display Incident Report
.navigation
  = link_to 'Edit', edit_incident_report_path(@incident_report)
  |
  \#{link_to 'Back', incident_reports_path}

= render 'form'

.navigation
  = link_to 'Edit', edit_incident_report_path(@incident_report)
  |
  \#{link_to 'Back', incident_reports_path}

私が見落としている本当にシンプルなものにならなきゃ。

4

1 に答える 1

0

これは、私が simple_form を使用していたためであり、simple_form が「表示」アクションで表示されると、フィールド値が 'value="54785"' 属性として html に配置されたためであることが判明しました。ブラウザで表示すると、ラベルと値はすべて正しく表示されますが、rspec では表示されません。

追加しなければなりませんでした

rendered.should have_tag 'input', :with => { :value => "54765", :name => 'incident_report[work_order]' }

それを機能させるために私の例に。

もっと良い解決策があるはずですが、少なくとも今はテストを続けることができます。

于 2012-08-18T00:14:40.703 に答える