0
votes

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)>'
1

1 Answers

1
votes

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.