Search code examples
ruby-on-railsrspeccapybararspec-railspoltergeist

Capybara config after each page load


I'm looking for a generic way to configure RSpec Capybara to do something after each page load within test example.

Example:

config.after_page_load do
  execute_script('window.analyticsEvents = []; window.analytics = function(name, properties) { analyticsEvents.push([name, properties]) }')
end

Then I can check that array in my feature test.

Only other option for a "global" configuration that I can think of is use if Rails.env.test? in the view.

Is there a better way?


Solution

  • I guess you could patch #visit to always execute your JS after each visit call - but it seems like maybe you're trying to do something that Capybara really isn't meant for, and may not make sense to be doing.