[英]Rspec Controller test not passing
My controller and my test file are bellow. 我的控制器和测试文件都在下面。
controllers/reports_controller.rb: controllers / reports_controller.rb:
def index
@reports = Report.all
end
specs/controllers/reports_controller_spec.rb: 规格/控制器/reports_controller_spec.rb:
RSpec.describe ReportsController, type: :controller do
let(:test_report) {
2.times.map {
create(:report, student: create(:student), report_options_attributes: [
{option: create(:option), note: "ole" }
])
}
}
describe "GET #index" do
before(:each) do
get :index
end
it "should be success" do
expect(response).to be_success
end
it "should render index template" do
expect(response).to render_template(:index)
end
it "should load all reports" do
expect(assigns(:report)).to match_array test_report
end
end
The last test is not working, but it should work. 最后一个测试不起作用,但是应该起作用。 What is wrong with it? 怎么了
index test is empty..you need to assert something to pass. 索引测试为空..您需要声明要通过的内容。
can you add.. assert_response :success
in index function. 你可以添加.. assert_response :success
在索引功能。
Your var is different from the controller. 您的var与控制器不同。 Use reports instead of report like this: 使用报告代替这样的报告:
it "should load all reports" do
expect(assigns(:reports)).to match_array test_report
end
It should work. 它应该工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.