save_and_open_page not working with capybara 2.0?

后端 未结 2 1367
太阳男子
太阳男子 2021-02-12 14:47

I just had my capybara updated to 2.0, and all of my save_and_open_page calls return an html page without styling. It has the style sheets links properly at the top of the page

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-12 15:08

    I was able to fix the problem with save_and_open_page after some blog browsing and digging. I have dropped the capybara_screenshot gem from my project. You can see my working code on my github test_capybara_screenshot repository. The solution that I figured out uses some pointers that I found on the capybara github site.

    Assumptions:

    • You are using rspec for testing.
    • Your app is already configured for using the asset pipeline.

    The first thing that I do is set it up so that assets are precompiled into a test directory. I do this by adding the following code into the spec/spec_helper.rb file within the RSpec.configure loop:

    config.before (scope = :suite) do
      %x[bundle exec rake assets:precompile]
    end
    

    I specify where the assets are pre-compiled to in the config/environments/test.rb file:

    config.assets.prefix = "assets_test"    # place test assets in public/assets_test directory
    config.action_controller.asset_host = "file://#{::Rails.root}/public"
    

    This makes it so that the test assets are independent of the development assets, and are only generated during a test suite run.

    If you do this, you will probably want to have git ignore the /public/assets* directories.

提交回复
热议问题