2016-09-11 19 views
1

通過遵循Rails教程,https://www.railstutorial.org/book/static_pages#sec-advanced_testing_setup學習Rails。Guard啓用彈簧時無法加載bundle/set

試圖建立衛隊自動測試運行,但我有以下錯誤,當我嘗試運行所有測試,

NO問題,當我把春天false

[email protected] FS_RailsSampleApp (master)*$ bundle exec guard 
20:06:46 - INFO - Guard::Minitest 2.4.4 is running, with Minitest::Unit 5.9.0! 
20:06:46 - INFO - Guard is now watching at '/Users/li-xinyang/Desktop/FS_RailsSampleApp' 
[1] guard(main)> 
20:06:53 - INFO - Run all 
20:06:53 - INFO - Running: all tests 
/usr/local/Cellar/ruby/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError) 
    from /usr/local/Cellar/ruby/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /Users/li-xinyang/Desktop/FS_RailsSampleApp/config/boot.rb:3:in `<top (required)>' 
    from bin/rake:2:in `require_relative' 
    from bin/rake:2:in `<main>' 

我試圖殺死彈簧進程並明確重新啓動彈簧服務器,但錯誤仍然存​​在。下面

的代碼片段是我的Gemfile和Guardfile,

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 :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] 

Guardfile,

# Defines the matching rules for Guard. 
guard :minitest, spring: true, all_on_start: false do 
    watch(%r{^test/(.*)/?(.*)_test\.rb$}) 
    watch('test/test_helper.rb') { 'test' } 
    watch('config/routes.rb') { integration_tests } 
    watch(%r{^app/models/(.*?)\.rb$}) do |matches| 
    "test/models/#{matches[1]}_test.rb" 
    end 
    watch(%r{^app/controllers/(.*?)_controller\.rb$}) do |matches| 
    resource_tests(matches[1]) 
    end 
    watch(%r{^app/views/([^/]*?)/.*\.html\.erb$}) do |matches| 
    ["test/controllers/#{matches[1]}_controller_test.rb"] + 
    integration_tests(matches[1]) 
    end 
    watch(%r{^app/helpers/(.*?)_helper\.rb$}) do |matches| 
    integration_tests(matches[1]) 
    end 
    watch('app/views/layouts/application.html.erb') do 
    'test/integration/site_layout_test.rb' 
    end 
    watch('app/helpers/sessions_helper.rb') do 
    integration_tests << 'test/helpers/sessions_helper_test.rb' 
    end 
    watch('app/controllers/sessions_controller.rb') do 
    ['test/controllers/sessions_controller_test.rb', 
    'test/integration/users_login_test.rb'] 
    end 
    watch('app/controllers/account_activations_controller.rb') do 
    'test/integration/users_signup_test.rb' 
    end 
    watch(%r{app/views/users/*}) do 
    resource_tests('users') + 
    ['test/integration/microposts_interface_test.rb'] 
    end 
end 

# Returns the integration tests corresponding to the given resource. 
def integration_tests(resource = :all) 
    if resource == :all 
    Dir["test/integration/*"] 
    else 
    Dir["test/integration/#{resource}_*.rb"] 
    end 
end 

# Returns the controller tests corresponding to the given resource. 
def controller_test(resource) 
    "test/controllers/#{resource}_controller_test.rb" 
end 

# Returns all tests for the given resource. 
def resource_tests(resource) 
    integration_tests(resource) << controller_test(resource) 
end 

兩個文件以上是從教程複製粘貼。

回答

1

你可以嘗試從您Guardfile改變執行行:

guard :minitest, spring: true, all_on_start: false do 

到:

guard :minitest, cmd: "bundle exec spring rake test" do 

,以控球后衛用正確的參數執行正確的春天

+0

謝謝我以後再試。 –

+0

謝謝。 @Ivan Zarea錯誤消失了,但是當我運行'bundle exec spring status'時,它顯示「Spring沒有運行」。 –