我正在为我的 Rails 应用程序功能编写一个测试,该功能处理学校的录取请求。我目前不工作的测试在提交入学申请表后测试入学申请的总数是否改变了 1。这是测试
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Address", with: "68 High St"
fill_in "Phone", with: "2035846857"
fill_in "Card", with: "4242424242424242"
fill_in "CVC", with: "557"
fill_in "admission_request_exp_month", with: "08"
fill_in "admission_request_exp_year", with: "2017"
end
it "should create a request", :js => true do
expect { click_button 'Submit Request' }.to change(AdmissionRequest, :count).by(1)
end
...
这是我运行测试时得到的
1) Admission requests pages new admission request with valid information should create a request
Failure/Error: expect { click_button 'Submit Request' }.to change(AdmissionRequest, :count).by(1)
count should have been changed by 1, but was changed by 0
但是如果我手动提交表格,一切正常,一个新的准入请求被保存到数据库中,并且计数改变了 1。可能是什么问题?我正在使用 rails 3.2.13 和 capybara 1.1.2
谢谢