I have a remote form that I want to test.
My feature test looks like this:
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'
#...
However, click_button 'Submit application'
breaks with the error:
*** ActionController::UnknownFormat Exception: ActionController::UnknownFormat
My controller only responds in JS. There are no redirects/renders. I want to eventually check the record exists in the database.
What do I need to do to ensure it doesn't break when the response is js
?
You need to run with a JS capable driver - https://github.com/teamcapybara/capybara#drivers - which in a default setup can be as easy as specifying the driver ( Capybara.javascript_driver = :selenium_chrome
for chrome via selenium, etc.) and setting js: true
metadata for the test. Also note that you can't use direct request methods ( get
, post
, etc) when using Capybara - you have to tell it to visit the page instead.
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'
#...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.