2016-08-21 56 views
0

我跟随this教程,直到现在我还没有遇到任何重大问题,但是当我突然尝试运行测试(或Guard)时,它突然开始失败。由于Bootstrap导轨测试失败 - 导轨4

对于每一次失败,它提醒我

ERROR["test_should_get_home", StaticPagesControllerTest, 1.3221390806138515] 
test_should_get_home#StaticPagesControllerTest (1.32s) 
ActionView::Template::Error:   ActionView::Template::Error: File to import not found or unreadable: bootstrap-sprockets. 
     Load paths: 
      /home/ubuntu/workspace/sample_app/app/assets/config 
      /home/ubuntu/workspace/sample_app/app/assets/images 
      /home/ubuntu/workspace/sample_app/app/assets/javascripts 
      /home/ubuntu/workspace/sample_app/app/assets/stylesheets 
      /home/ubuntu/workspace/sample_app/vendor/assets/javascripts 
      /home/ubuntu/workspace/sample_app/vendor/assets/stylesheets 
      /usr/local/rvm/gems/ruby-2.3.0/gems/jquery-rails-4.1.1/vendor/assets/javascripts 
      /usr/local/rvm/gems/ruby-2.3.0/gems/coffee-rails-4.2.1/lib/assets/javascripts 
      /usr/local/rvm/gems/ruby-2.3.0/gems/actioncable-5.0.0.1/lib/assets/compiled 
      /usr/local/rvm/gems/ruby-2.3.0/gems/turbolinks-source-5.0.0/lib/assets/javascripts 
      app/assets/stylesheets/custom.scss:1 
      app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb___4391039624438268474_46194740' 
      test/controllers/static_pages_controller_test.rb:15:in `block in <class:StaticPagesControllerTest>' 

,我可以破译 - 它试图利用引导和不能。

也许我对TDD不够熟悉,但为什么它试图让bootstrap渲染标题?这是由于部分?

我发现了很多其他帖子,但是大多数人都死了,或者来自Rails 3,只是重新启动服务器解决了它。

我能解决它,但修改我的Gemfile。我从顶部移动了gem 'bootstrap-sass', '3.3.6',变成了

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

块。我认为块外的任何宝石都是永久加载的,但事实并非如此?我是否应该在未来坚持这种风格?

(配售为符号起见整个的Gemfile)

source 'https://rubygems.org' 

gem 'rails',  '5.0.0.1' 
gem 'puma',   '3.4.0' 
gem 'sass-rails', '5.0.6' 
gem 'uglifier',  '3.0.0' 
gem 'coffee-rails', '4.2.1' 
gem 'jquery-rails', '4.1.1' 
gem 'turbolinks', '5.0.1' 
gem 'jbuilder',  '2.4.1' 

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


group :development, :test do 
    gem 'sqlite3', '1.3.11' 
    gem 'byebug', '9.0.0', platform: :mri 
end 

group :development do 
    gem 'web-console',   '3.1.1' 
    gem 'listen',    '3.0.8' 
    gem 'spring',    '1.7.2' 
    gem 'spring-watcher-listen', '2.0.0' 
end 

group :test do 
    gem 'rails-controller-testing', '0.1.1' 
    gem 'minitest-reporters',  '1.1.9' 
    gem 'guard',     '2.13.0' 
    gem 'guard-minitest',   '2.4.4' 
end 

group :production do 
    gem 'pg', '0.18.4' 
end 

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 

编辑:添加在两个测试中的要求。

应用测试

ENV['RAILS_ENV'] ||= 'test' 
require File.expand_path('../../config/environment', __FILE__) 
require 'rails/test_help' 
require "minitest/reporters" 
Minitest::Reporters.use! 

class ActiveSupport::TestCase 
    # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 
    fixtures :all 
    include ApplicationHelper 

    # Add more helper methods to be used by all tests here... 
end 

具体测试

需要 'test_helper'

class SiteLayoutTest < ActionDispatch::IntegrationTest 

    test "layout links" do 
    get root_path 
    assert_template 'static_pages/home' 
    assert_select "a[href=?]", root_path, count: 2 
    assert_select "a[href=?]", help_path 
    assert_select "a[href=?]", about_path 
    assert_select "a[href=?]", contact_path 
    get contact_path 
    assert_select "title", full_title("Contact") 
    get signup_path 
    assert_select "title", full_title("Sign-Up") 
    end 
end 
+0

找你问题停止从'app/assets/stylesheets/custom.scss:1'开始是否有导入指令?你的失败测试是怎样的? – slowjack2k

+0

@ slowjack2k本身添加了精确的测试。 – DNorthrup

回答

0

我观察到同样的ActionView::Template::Error: File to import not found or unreadable: bootstrap-sprockets.症状合并我filling-in-layout支进master在后。

我认为问题在于Git更新或无法更新某个文件的修改时间戳。我相信在运行rails test时,阻止Rails资产管道中的预处理器引擎更新某些生成的文件。

我通过运行git ls-files | xargs touch解决了问题。

0

合并到主分支之前进行快速检查正在运行的春天服务器

ps aux | grep spring 

,然后用

spring stop 

pkill -15 -f spring