brad
brad

Reputation: 9773

save_and_open_page has stopped serving up my css

My testing setup was working very nicely serving up pages correctly formatted with css whenever I called save_and_open_page from within a test. I then set up some javascript tests and made a few changes to my setup (sorry I can't detail them all - I haven't documented things well enough). After making changes I now get unformatted html in the browser when I call save_and_open_page.

Here's my spec/spec_helper.rb

require 'rubygems'
require 'spork'

Spork.prefork do

  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  require 'capybara/rspec'
  require 'factory_girl'
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  RSpec.configure do |config|
    config.fixture_path = "#{::Rails.root}/spec/fixtures"
    config.add_setting(:seed_tables)
    config.seed_tables = %w(notifications drug_names drug_modes drug_prefs db_tables db_columns column_values)
    config.use_transactional_fixtures = false
    config.before(:suite) do
      DatabaseCleaner.strategy = :truncation, {except: config.seed_tables}
    end
    config.before(:each) do
      DatabaseCleaner.start
    end
    config.after(:each) do
      DatabaseCleaner.clean
    end
    config.infer_base_class_for_anonymous_controllers = false
    config.include Features::SessionHelpers, type: :feature
    config.order = "random"
  end
  Spork.each_run do
    FactoryGirl.reload
  end
end

I have the following gems installed in my test environment;

gem 'rspec-rails', '2.13.0'
gem 'guard-rspec', '2.4.1'
gem 'rb-fsevent', '0.9.3'
gem 'terminal-notifier-guard', '1.5.3'
gem 'guard-spork', '1.5.0'
gem 'spork', '0.9.2'
gem 'capybara', '2.1.0'
gem 'timecop', '0.5.9.2'
gem 'launchy', '2.2.0'
gem 'factory_girl_rails', '4.2.1'
gem 'shoulda', '3.3.2'
gem 'faker', '1.1.2'
gem 'database_cleaner', '0.9.1'
gem 'selenium-webdriver', '2.32.1'

Any clues as to what I've done to stop this from working properly?

Upvotes: 2

Views: 1824

Answers (2)

hani elabed
hani elabed

Reputation: 830

Just an FYI, save_and_open_page works courtesy of the wonderful people of these 2 links. This is what I have at the bottom of my spec_helper.rb to make it work

# to 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 or
# wherever you want. See original issue here:
#https://github.com/jnicklas/capybara/pull/609
# and final resolution here:
#https://github.com/jnicklas/capybara/pull/958
Capybara.asset_host = "http://localhost:3000"

enjoy and thank you sdhull and jnicklas and all who worked on it

Hani

Upvotes: 15

berkes
berkes

Reputation: 27593

This was removed from Capybara, in pull 609

Jnicklas:

I am making an executive decision here by virtue of my status as Benevolent Dictator for Life of Capybara:

Asset rewriting has got to go. It is seriously the worst part of the entire Capybara code base. It's a terrible hack which has never worked right in the first place and the slim benefit it gives us can easily be achieved by superior debugging methods, like running the same test in Selenium and halting execution via e.g. sleep, gets or binding.pry.

I'm sorry if this annoys some of you, but it's my job to make the tough decisions about what goes in and what stays out. If I don't do that job and simply accept everything, we will not end up with a good result. So I hope that you can accept this decision even though you may disagree with it.

As per Save_and_open_page not picking up scss markup you could consider making screenshots with the capybara-screenshot-gem.

This gem will introduce save_and_open_screenshot.

However, as jnicklas mentions in the discussion in the pull-request there is a good reason to not want this feature at all:

...because RackTest doesn't have CSS and JS, so now you're seeing the page differently from how Capybara would

Upvotes: 4

Related Questions