【问题标题】:Undefined method accept_modal for Capybara::Webkit::DriverCapybara::Webkit::Driver 的未定义方法 accept_modal
【发布时间】:2017-11-08 03:46:27
【问题描述】:

在 Rails 应用程序中,我使用 RSpec(与 Ca​​pybara 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 没有。

【问题讨论】:

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


    【解决方案1】:

    您使用的 capybara-webkit 已经严重过时(1.1.0 于 2013 年 12 月发布),不支持统一的 Capybara modal API(它在 capybara-webkit 1.1.0 发布时不存在)已发布),并且没有从 Capybara::Driver::Base 派生它的驱动程序类,因此如果驱动程序尚未实现/支持某个功能,您现在不会得到“NotSupportedByDriverError” - 更新到最新的capybara-webkit(如果你想使用capybara 2.14.0+,你可能需要使用master分支,否则你会卡在capybara 2.13.x)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      相关资源
      最近更新 更多