Capybara :: Webkit :: Driver的未定义方法accept_modal

时间:2017-06-07 00:22:30

标签: ruby-on-rails rspec capybara rspec-rails capybara-webkit

在Rails应用程序中,我使用RSpec(使用Capybara Webkit)测试删除链接是否正常工作。

在我的Rails模板中,我有:

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

这是我的规格:

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

我收到错误:

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

它使用了正确的驱动程序(Webkit),但它似乎找不到accept_modal(必须由page.accept_confirm调用)。

我正在使用:

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

请注意,使用以下内容将起作用

click_link 'Delete'
page.driver.browser.accept_js_confirms

但我想了解为什么accept_confirm没有。

1 个答案:

答案 0 :(得分:0)

您使用的capybara-webkit已大量过时(2013年12月发布了1.1.0),不支持统一的Capybara模式API(当capybara-webkit 1.1.0版本时它不存在释放),并没有从Capybara :: Driver :: Base派生它的驱动程序类,所以如果某个功能尚未由驱动程序实现/支持,您将无法获得“NotSupportedByDriverError” - 更新到最新的capybara-webkit(如果你想使用capybara 2.14.0+,你可能需要使用master分支,否则你将被困在capybara 2.13.x)