Using Capybara with Poltergeist to click on a link with a data-method='delete'
attribute.
Capybara moves on as if the link was successfully clicked, but no actual request hits the server.
Test logs show all the steps leading up to the displayed page ... but no request for the appropriate link.
It finds the correct link with no problem and thinks it's clicked it.
I should point out it's not a :remote link and it works in development
Any ideas?
Here's the code:
scenario "deletes a document", js: true do
set_auto_accept_for_alert_and_confirm_dialogs
sign_in_admin admin
visit admin_dashboard_path
find(:css, '#mediaDropdown').trigger('click')
find(:css, '#documents_link').click
find(:css, "#delete_link_#{document.id}").click
expect(current_path).to eq admin_documents_path
expect(Document.all.size).to eq 0
expect(page).to have_content(I18n.t('notices.admin.documents.destroy.success'))
end
I've extended the wait time, added a long sleep & usedbyebug
immediately before the 'delete' link & tried calling it in the console.
Capybara(2.10.1) - Poltergeist(1.11.0) - Rails(4.2.7.1) - jquery-rails(4.2.1) - turbolinks(5.0.1)
I turned on debugging with:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, { js_errors: true, debug: true })
end
This raised the javascript error Can't find variable: $
- so jQuery wasn't being loaded.
I checked the test log to see if the javascript file was being called - it was.
I changed the javascript file to change some text on the page - but nothing happened. So the problem appeared to be with the asset pipeline.
In the end, the problem was because a .sprokets-manifest
file had been created in the public\assets
folder, which was otherwise empty.
I've never pre-compiled the assets on this app, so I've no idea where the manifest file came from.
Deleting the .sprokets-manifest
file was an easy fix.