我跟隨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
找你問題停止從'app/assets/stylesheets/custom.scss:1'開始是否有導入指令?你的失敗測試是怎樣的? – slowjack2k
@ slowjack2k本身添加了精確的測試。 – DNorthrup