我的控制器和測試文件如下。Rspec控制器測試未通過
控制器/ reports_controller.rb:
def index
@reports = Report.all
end
規格/控制器/ 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
最後一次測試是不工作的,但它應該工作。它有什麼問題?
是的,工作。謝謝 – Thatsthati