Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.