-1

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
Moeeee100
  • 1
  • 2

1 Answers1

1

You state that uncommenting format.html didn'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 the click_on 'Add New Location' line which appears to the only part of your test that would call a new action. 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/RSpecs driven_by (for Rails 6+ and system specs) or Capybaras default_driver and javascript_driver settings 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

  1. You should never be using RSpecs general matchers (eq, etc) with Capybara related info
  2. You should not be setting Capybara global settings (default_max_wait_time) inside your test. Instead set the per command options for max wait time, or use using_wait_time if needed for multiple commands.
  3. There's no point checking for content that you then attempt to click, since the click_on is also checking for its existence

taking those into account your test should be written more like

visit locations_profile_path(@provider)
expect(page).to have_current_path("/profile/#{@provider.id}/locations")
expect(page).to have_content("All Practice Locations")
click_on 'Add New Location', wait: 20
Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78