我有一个失败的 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 模板
规范/视图/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}
必须是一些非常简单的东西,我忽略了。