Skip to content

Instantly share code, notes, and snippets.

@lujanfernaud
Created October 31, 2018 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lujanfernaud/84c0767fc8d5be4e91da7329859e6de2 to your computer and use it in GitHub Desktop.
Save lujanfernaud/84c0767fc8d5be4e91da7329859e6de2 to your computer and use it in GitHub Desktop.
Rails and Capybara: Open Page With Assets

Rails and Capybara: Open Page With Assets

To automatically open pages saved when using save_and_open_page we need to add the launchy gem to the test environment.

# Gemfile

group :test do
  gem 'launchy', '~> 2.4', '>= 2.4.3'
end

To allow CSS and JavaScript to be loaded we need to specify the asset host and precompile assets for the test environment.

# rails_helper.rb

# Allow CSS and JavaScript to be loaded when we use save_and_open_page.
# The development server must be running at localhost:3000 as specified below.
# Assets need to be precompiled.
# https://github.com/jnicklas/capybara/pull/958
Capybara.asset_host = "http://localhost:3000"

Command line:

rails assets:precompile RAILS_ENV=test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment