我有一个我要测试的远程表单。
我的功能测试看起来像:
RSpec.feature 'User creates a foobar' do
scenario 'they see the foobar on the page' do
get '/apply', :js
fill_in 'Name', with: 'Joe Bloggs'
click_button 'Submit application'
#...
但是, click_button 'Submit application'
随着错误而断裂:
*** ActionController::UnknownFormat Exception: ActionController::UnknownFormat
我的控制器仅在JS中做出响应。没有重定向/渲染。我想最终检查数据库中的记录。
当响应为 js
时,我需要做什么才能确保它不会破裂?
您需要使用能够JS的驱动程序运行-https://github.com/teamcapybara/capybara#drivers-在默认设置中,它可以像指定驱动程序一样容易(Capybara.javascript_driver = :selenium_chrome
用于Chrome通过硒等(,并将js: true
元数据设置为测试。另请注意,使用Capybara时,您不能使用直接的请求方法(get
,post
等( - 您必须告诉其访问页面。
RSpec.feature 'User creates a foobar', js: true do # `js: true` applies to all scenarios in this feature - could be put on single scenario instead if desired
scenario 'they see the foobar on the page' do
visit '/apply'
fill_in 'Name', with: 'Joe Bloggs'
click_button 'Submit application'
#...