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}
私が見落としている本当にシンプルなものにならなきゃ。