Reputation: 27417
Learning Rails by following Rails tutorial, https://www.railstutorial.org/book/static_pages#sec-advanced_testing_setup.
Trying to set up Guard for auto test running but I have the following error when I try to run all tests,
There is NO problem when I turn spring to false
.
li-xinyang@MachineX 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>'
I have tried to kill the spring process and explicitly restart the spring server again, but the error is still there.
The code snippet below is my Gemfile and 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
Both files above are copy-paste from the tutorial.
Upvotes: 1
Views: 181
Reputation: 2174
You can try to change the executing line in your Guardfile from:
guard :minitest, spring: true, all_on_start: false do
to:
guard :minitest, cmd: "bundle exec spring rake test" do
in order to point Guard to execute the right Spring with the right arguments
Upvotes: 1