Question

I have a very simple set of tests (from the Rails Tutorial), but all tests fail with this error:

File to import not found or unreadable: bootstrap

Any ideas what is happening?

Details Below ==================================

Example test:

  describe "Help page" do
    it "should have the content 'Help'" do
        visit '/static_pages/help'
        expect(page).to have_content('Help')
    end
    # Title test.
      it "should have the right title" do
        visit '/static_pages/help'
        expect(page).to have_title("#{base_title} | Help")
      end
  end

Test failure message:

8) Static pages Home page should have the base title
     Failure/Error: visit '/static_pages/home'
     ActionView::Template::Error:
       File to import not found or unreadable: bootstrap.
       Load paths:
         /Users/donald/Projects/rails_projects/sample_app/app/assets/images
         /Users/donald/Projects/rails_projects/sample_app/app/assets/javascripts
         /Users/donald/Projects/rails_projects/sample_app/app/assets/stylesheets
         /Users/donald/Projects/rails_projects/sample_app/vendor/assets/javascripts
         /Users/donald/Projects/rails_projects/sample_app/vendor/assets/stylesheets
         /Users/donald/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/turbolinks-1.1.1/lib/assets/javascripts
         /Users/donald/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/jquery-rails-3.0.4/vendor/assets/javascripts
         /Users/donald/.rvm/gems/ruby-2.0.0-p247@railstutorial_rails_4_0/gems/coffee-rails-4.0.1/lib/assets/javascripts
         (in /Users/donald/Projects/rails_projects/sample_app/app/assets/stylesheets/custom.css.scss:1)
     # ./app/assets/stylesheets/custom.css.scss:1
     # ./app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__1482688987114081587_70170540160220'
     # ./spec/requests/static_pages_spec.rb:14:in `block (3 levels) in <top (required)>'

How I require Bootstrap:

  1. I import bootstrap in my gemfile gem 'bootstrap-sass', '2.3.2.0'.
  2. I require it in my custom.css.sass file: @import "bootstrap";.
  3. I require it in my application.css file: *= require_self *= require_tree .

And my site renders correctly with bootstrap's styling.

Was it helpful?

Solution

Some people are having this problem if they have upgraded from rails 3.x to 4 and they still have a group :assets do block in your gemfile. In rails 4 you have to get rid of the assets group

delete "group :assets do" and "end" from your gemfile, if they exist.

group :assets do
gem 'bootstrap-sass'
end

Other people with this error were able to fix it by simply restarting the server, still others were able to fix the same error with a small change to the lib/bootstrap-sass.rb file as documented here in a pull request.

OTHER TIPS

I had the same issue in rails 4. I had imported "bootstrap" and "bootstrap-sprockets" into my scss file and HTML page worked fine, but rake test failed.

I have added gem 'bootstrap-sass' to groups :test and :development in my gemfile, as follows:

group :assets, :test, :development do gem 'bootstrap-sass', '2.3.2.0 end

I don't know whether this is the best solution, but it works for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top