【发布时间】:2015-09-15 11:37:29
【问题描述】:
我正在尝试在我的用户目录中创建一个所有 Rails 项目都可以运行的 .Guardfile。
.Guardfile 内容概述如下:
# Defines the matching rules for Guard.
guard :test, all_on_start: false do
watch(%r{^test/(.*)/?(.*)_test\.rb$})
watch('test/test_helper.rb') { 'test' }
watch('config/routes.rb') { 'test' }
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
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
但是,当我在 rails 目录的根目录中运行 guard 时,我遇到了以下问题..
11:53:04 - INFO - Guard::Test 2.0.6 is running, with Test::Unit 3.1.3!
11:53:04 - INFO - Guard is now watching at '/../../Documents/Projects/..'
[1] guard(main)>
11:53:06 - INFO - Run all
11:53:06 - INFO - Running all tests
/*/*/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/guard-test-2.0.6/lib/guard/test/guard_test_runner.rb:1:in `require': cannot load such file -- test/unit/ui/console/testrunner (LoadError)
from /../../.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/guard-test-2.0.6/lib/guard/test/guard_test_runner.rb:1:in `<top (required)>'
from -e:1:in `require'
[1] guard(main)>
有人有什么想法吗?
【问题讨论】:
标签: ruby-on-rails ruby tdd minitest guard