2017-06-07 23 views
1

在Rails應用程序中,我使用RSpec(帶有Capybara Webkit)來測試Delete鏈接是否正在工作。未定義的方法accept_modal用於Capybara :: Webkit :: Driver

在我的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沒有。

回答

0

您正在使用的capybara-webkit大量過時(1.1.0在2013年12月發售),不支持統一的Capybara模式API(當capybara-webkit 1.1.0時不存在被釋放),並沒有從Capybara :: Driver :: Base派生它的驅動類,所以如果某個特性尚未被驅動實現/支持,那麼你不會得到現在得到的「NotSupportedByDriverError」 - 更新爲最新的水豚-webkit(如果你想使用capybara 2.14.0+,你可能需要使用master分支,否則你會被卡住在水豚2.13.x)