Undefined method accept_modal for Capybara::Webkit::Driver

て烟熏妆下的殇ゞ 提交于 2019-12-13 17:19:00

问题


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:


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)



来源:https://stackoverflow.com/questions/44401643/undefined-method-accept-modal-for-capybarawebkitdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!