Capybara :: Webkit :: Driver的未定义方法accept_modal
在Rails应用程序中,我使用RSpec(使用Capybara Webkit)来测试Delete链接是否正常工作。
在我的Rails模板中,我有:
这是我的规格:
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 #
它使用正确的驱动程序(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
没有。
您使用的capybara-webkit大规模过时(2013年12月发布了1.1.0),不支持统一的Capybara模态API(当capybara-webkit 1.1.0发布时它不存在),并没有从Capybara :: Driver :: Base派生出它的驱动程序类,所以如果某个function尚未由驱动程序实现/支持,你就不会得到你现在会得到的“NotSupportedByDriverError” – 更新到最新的capybara- webkit(如果你想使用capybara 2.14.0+,你可能需要使用master分支,否则你将被困在capybara 2.13.x)