大佬教程收集整理的这篇文章主要介绍了ruby-on-rails – Capybara不等待ajax完成,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
feature 'Processing step three',:js => true do BACkground do to_step_2 to_step_3 end scenario 'CreaTing job',js: true do within '#login' do fill_in 'Email',with: @customer.email fill_in 'password',with: @customer.password click_button 'Login' end expect { click_link 'Create job' }.to change(Job,:count).by(1) end end
因此,当用户填写了所有内容时,最后他们点击创建作业,就像我的测试所描述的那样.当我手动操作时,这工作正常,但当我运行我的规格时,我得到.
1) CreaTing a new job Processing step three CreaTing job Failure/Error: expect { click_link 'Create job' }.to change(Job,:count).by(1) count should have been changed by 1,but was changed by 0 # ./spec/features/creaTing_a_new_job_spec.rb:103:in `block (3 levels) in <top (required)>'
现在,如果我查看我的测试日志,我可以看到,在插入作业之前,该水豚会运行计数
Completed 200 OK in 36ms (Views: 6.0ms | ActiveRecord: 11.2ms) Started POST "/api/jobs" for 127.0.0.1 at 2013-12-08 14:15:00 +0100 Processing by Api::JobsController#create as JSON Parameters: {"job"=>{"description"=>"This is a test description of the service i would like to receive.","zip"=>"2400","available_from"=>"24 - 12 - 2013","available_next"=>false,"customer_id"=>"1","service_id"=>"1","service_field_id"=>"1"}} Unpermitted parameters: zip (11.3ms) SELECT COUNT(*) FROM "jobs" (1.2ms) BEGIN SQL (2.5ms) INSERT INTO "jobs" ("available_from","available_next","created_at","customer_id","description","service_field_id","service_id","updated_at") VALUES ($1,$2,$3,$4,$5,$6,$7,$8) RETURNING "id" [["available_from",Tue,24 Dec 2013 00:00:00 UTC +00:00],["available_next",false],["created_at",Sun,08 Dec 2013 13:15:00 UTC +00:00],["customer_id",1],["description","This is a test description of the service i would like to receive."],["service_field_id",["service_id",0],["updated_at",08 Dec 2013 13:15:00 UTC +00:00]] (0.5ms) COMMIT
我如何强迫Capybara举行风帆?
如果使用Capybara,测试就像一个真实的用户,你应该期待一些UI更改而不是数据库更改,因为真正的用户无法看到db中发生了什么.
在此测试中,db断言立即执行,甚至比浏览器驱动程序向服务器发送数据的速度更快,因此数据为零.
修理,
>首先删除内部块.这似乎并不重要.如果我记得正确的话,期望最好不要在不同的行动块中.所以这样做是为了安全.
>添加UI期望.然后Capybara将等到效果出现.
所以,
scenario 'CreaTing job',js: true do fill_in 'Email',with: @customer.email fill_in 'password',with: @customer.password click_button 'Login' # Assume your page will show user name after signing in expect(pagE).to have_content(@customer.Name) end
如果您真的想测试数据库更改,可以在UI期望之后添加该期望,但我不建议这样做.
以上是大佬教程为你收集整理的ruby-on-rails – Capybara不等待ajax完成全部内容,希望文章能够帮你解决ruby-on-rails – Capybara不等待ajax完成所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。