0

我正在为 Rails 3 开发一个 gem,在 travis-ci.org 在 Ruby 1.8.7 下运行它时遇到了一个错误:

/home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:874:in `_run_suite': undefined method `run' for #<TestActivist:0xb6936dd4> (NoMethodError)
69  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:866:in `map'
70  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:866:in `_run_suite'
71  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:853:in `_run_suites'
72  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:853:in `map'
73  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:853:in `_run_suites'
74  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:826:in `_run_anything'
75  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:1015:in `run_tests'
76  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:1002:in `send'
77  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:1002:in `_run'
78  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:1001:in `each'
79  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:1001:in `_run'
80  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:990:in `run'
81  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/minitest-3.5.0/lib/minitest/unit.rb:748:in `autorun'
82  from /home/travis/.rvm/gems/ruby-1.8.7-p370/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:21
83rake aborted!
84Command failed with status (1): [/home/travis/.rvm/rubies/ruby-1.8.7-p370/b...]

这是失败工作的链接:https ://travis-ci.org/#!/pokonski/public_activity/jobs/2586051

在 Ruby > 1.8.7 中一切正常。

我的 .gemspec 的相关部分:

  s.add_dependency 'activerecord', '>= 3.0.0'
  s.add_dependency 'activesupport', '>= 3.0.0'
  s.add_dependency 'actionpack', '>= 3.0.0'
  s.add_dependency 'i18n', '>= 0.5.0'

  if RUBY_VERSION == "1.8.7"
    s.add_development_dependency 'minitest', '>= 3.2.0'
  else
    s.add_development_dependency 'simplecov', '>= 0.6.4'
  end

  s.add_development_dependency 'bundler', '>= 1.1'
  s.add_development_dependency 'rake', '>= 0.9'
  s.add_development_dependency 'sqlite3'
  s.add_development_dependency 'mocha', '>= 0.12.1'
  s.add_development_dependency 'rails', '>= 3.0.0' # generators test

和宝石文件:

source :rubygems

gemspec

gem 'yard'

有趣的是,当使用 ruby​​-1.8.7-p370 在本地运行测试时,使用不同的缺失方法会出现错误:

test_resolving_values(TestCommon):
NoMethodError: undefined method `mock' for #<TestCommon:0x7ffdc8a79388>
    /home/piotrek/projekty/public_activity/test/test_common.rb:85:in `test_resolving_values'

失败行的更多源代码:https ://github.com/pokonski/public_activity/blob/master/test/test_common.rb#L85

有人知道发生了什么吗?

4

1 回答 1

0

原来是因为 test_generators.rb 使用了 Rails::Generators::TestCase,而后者又继承自 TestUnit。

因此,Mocha 错误地修补了 Test::Unit 而不是 MiniTest。解决方案是test_helper在 test_generators.rb 中要求并将 MiniTest gem 强制为 3.2.0 版本。

此提交中的完整解决方案:https ://github.com/pokonski/public_activity/commit/731e953068297c7aa6f6f7e2b2251c79843943a1

于 2012-10-08T21:26:01.340 回答