1

I'm using rails 4 and rspec with capybara for testing. I want to disable css in my test environment. How can I do that? Can anyone help me.

2 Answers 2

2

The simplest way - skip CSS files loading in your /app/views/layouts/application.html.erb for test env.:

<% unless Rails.env.test? %>
  <%= stylesheet_link_tag    "application", :media => "all" %>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

0

Capybara allows you to blacklist specific URLs from being loaded. You can utilize this feature to block the loading of your CSS files. For example if your CSS is loaded from /assets/application.css:

RSpec.configure do |config|
  config.before(:each, js: true) do
    page.driver.browser.url_blacklist = [
      "http://127.0.0.1:#{page.server.port}/assets/application.css"
    ]
  end
end

You can confirm what assets are getting loaded by turning on Capybara's debugging. To enable debugging simply set the driver to :webkit_debug instead of :webkit

Capybara.javascript_driver = :webkit_debug

2 Comments

But I'm using poltergeist driver for capybara.
I found this marcgg.com/blog/2015/01/05/…. But not getting how to add this file to disable css in specs. Any ideas from you for this please.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.