ruby-on-rails - rake spec 在 specs 之后运行测试

标签 ruby-on-rails ruby ruby-on-rails-3 rspec rake

当我在我的 Rails 项目中运行 rake spec 时,它会执行所有规范,然后尝试运行测试(如 rake test):

$ rake spec
ruby -S rspec ./spec/... #file list
# --> ...  normal RSpec output
Finished in 11.11 seconds
111 examples, 0 failures, 11 pending

# --> here starts the problem <--
Run options: 

# Running tests:

Finished tests in 0.000343s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

你知道吗,为什么它会尝试运行 Test::Unit 测试,即使我没有这些测试? (我什至没有test/目录)

编辑: 当我运行其他 rake 命令时,它们完成了它们的工作,但随后以错误结束,例如:

$ rake about
About your application's environment
Ruby version             1.9.3 (i686-linux)
RubyGems version         1.8.24
Rack version             1.4
Rails version            3.2.3
JavaScript Runtime       therubyracer (V8)
Action Pack version      3.2.3
Active Support version   3.2.3
Middleware               ActionDispatch::Static, Rack::Lock, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root         /path/to/project
Environment              development
path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: about (ArgumentError)
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:21:in `run'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
        from path/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'

最佳答案

任何带有 require test/unit 的文件都会启用一个 at_exit Hook ,该 Hook 会尝试运行测试。

如果从您的 rake 任务加载的任何文件执行此操作,at_exit Hook 将尝试使用您的 rake 命令的最后一部分作为要运行的测试的名称来运行测试。在 rake about 的情况下,它会搜索名为 about 的不存在的测试。

当我的 Gemfile 中有 shoulda gem 时,我遇到了问题。我通过将其包含在 Gemfile 中解决了这个问题:

gem 'test-unit', :require => "test/unit"

关于ruby-on-rails - rake spec 在 specs 之后运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12261798/

相关文章:

ruby-on-rails - Capistrano 错误

ruby-on-rails - Rails ActiveRecord : Skip validations for associations

Ruby 检查与 Rspec 中的 to_s

ruby-on-rails-3 - 使用 Rails 在 Net::HTTP::Get.new 中设置自定义超时

ruby-on-rails-3 - 在 Rails 3 中, = 和 allocate_attributes 之间有区别吗?

jquery - 单击后退按钮时呈现的原始 javascript

ruby-on-rails - 如何以 rails 形式处理多个模型

ruby-on-rails - sidekiq 中的 perform_in 和 perform_async 有什么区别?

ruby - Splat 在非最终位置

ruby - 如何在 ruby​​ 中打开安全连接