This is the error when i run the capybara test:
Failure/Error:
respond_to do |format|
#format.html
format.js
end
ActionController::UnknownFormat:
ActionController::UnknownFormat
This is from the controller file: (uncommenting format.html didn't work)
def new
@location = @provider.locations.new
@address = @location.build_address
@addresses = []
respond_to do |format|
#format.html
format.js
end
This is the capybara code
describe "this tab" do
it "shows data" do
visit locations_profile_path(@provider)
expect(current_path).to eq("/profile/#{@provider.id}/locations")
expect(page).to have_content("All Practice Locations")
expect(page).to have_content('Add New Location')
Capybara.default_max_wait_time = 20
click_on 'Add New Location'
end
end
You state that uncommenting
format.htmldidn't work, but I'm betting it failed with a different error message, because you don't have an html view. I'm also assuming that the error message you're seeing is coming from theclick_on 'Add New Location'line which appears to the only part of your test that would call anewaction. Without seeing the code in your page triggered by clicking on 'Add New Location' I can't be 100% sure what the issue is, but based on the error I'm guessing that you're not actually using the capybara-webkit driver (even though the question is tagged with that). Really you shouldn't be using the capybara-webkit driver nowadays anyway since it was obsolete years ago. Rather you should be looking at one of the up-to-date maintained drivers like Selenium, etc. Depending on which version of Rails you're using and what type of tests you're writing you'll want to either look at Rails/RSpecsdriven_by(for Rails 6+ and system specs) or Capybarasdefault_driverandjavascript_driversettings if writing feature specs - click_on 'Add New Location'. If you're not correctly selecting the driver to be used then it would default to the rack-test driver which doesn't support JS and therefore would never make a request for a JS format response.Other comments on your test
using_wait_timeif needed for multiple commands.taking those into account your test should be written more like