1
votes

In a Rails app, I'm using RSpec (with Capybara Webkit) to test that a Delete link is working.

In my Rails template I have:

<%= link_to 'Delete', movie_path(@movie), 
                      method: :delete, data: { confirm: 'Are you sure?' } %>

And this is my spec:

require 'rails_helper'

describe "Deleting a movie", js: true do
  it "destroys the movie and shows the movie listing without the deleted movie" do
    movie = Movie.create(movie_attributes)

    visit movie_path(movie)

    page.accept_confirm do
     click_link 'Delete'
    end

    expect(current_path).to eq(movies_path)
    expect(page).not_to have_text(movie.title)
  end
end

I get the error:

NoMethodError:
   undefined method `accept_modal' for #<Capybara::Webkit::Driver:0x007febc2214908>

It's using the right driver (Webkit) but it doesn't seem to find accept_modal (which must be called by page.accept_confirm).

I'm using:

capybara (2.14.0)
capybara-webkit (1.1.0)
rails (5.1.1)
rspec (3.6.0)
rspec-rails (3.6.0)

Note that using the following will work:

click_link 'Delete'
page.driver.browser.accept_js_confirms

But I'd like to understand why accept_confirm does not.

1

1 Answers

0
votes

The capybara-webkit you are using is massively out of date (1.1.0 was realeased in December of 2013), didn't support the unified Capybara modal API (it didn't exist when capybara-webkit 1.1.0 was released), and didn't derive it's driver class from Capybara::Driver::Base, so you don't get the "NotSupportedByDriverError" you would get nowadays if a feature was not yet implemented/supported by a driver - update to the latest capybara-webkit (you may need to use the master branch if you want to use capybara 2.14.0+, otherwise you'll be stuck at capybara 2.13.x)