Reputation: 5
I am trying to set up a test for a validation in a "Link_to" helper in rails when it has a => data: {confirm: "Are you sure?"}
I have tried Accept_confirm and Accept_Alert but none of this has worked. The errors shows: Capybara::NotSupportedByDriverError: Capybara::Driver::Base#accept_modal
describe 'delete' do
it 'y existe un enlace para borrar Post' do
@post = FactoryBot.create(:post)
visit posts_path
accept_confirm("Are you sure?") do
click_link("delete#{@post.id}")
end
expect(page.status_code).to eq(200)
end
end
<td>
<%= link_to 'Borrar', post_path(post), method: :delete, id: "delete#{post.id}", data: {confirm: "Are you sure?" }%>
</td>
The complete error message says: 1) navegate delete y existe un enlace para borrar Post Failure/Error: accept_confirm("Are you sure?") do click_link("delete#{@post.id}") end
Capybara::NotSupportedByDriverError:
Capybara::Driver::Base#accept_modal
# ./spec/features/post_spec.rb:45:in `block (3 levels) in <top (required)>'
Upvotes: 0
Views: 2096
Reputation: 366
You can add js: true
to switch to the Capybara.javascript_driver
describe 'delete', js: true do
it 'y existe un enlace para borrar Post' do
@post = FactoryBot.create(:post)
visit posts_path
accept_confirm("Are you sure?") do
click_link("delete#{@post.id}")
end
expect(page.status_code).to eq(200)
end
end
Documentation here : https://github.com/teamcapybara/capybara/blob/master/README.md#using-capybara-with-rspec
Upvotes: 2
Reputation: 49870
You're running your tests using a driver which doesn't support JS (probably the default rack_test
driver). As such JS driven modal boxes can't show up, and the modal handling methods aren't supported. You'll have to run your tests via a driver that supports JS if you want to use JS features of the page - https://github.com/teamcapybara/capybara/blob/master/README.md#drivers.
Upvotes: 1