我正在为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中的一切都运行良好&gt; 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
和Gemfile:
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
任何人都知道发生了什么事?
答案 0 :(得分:0)
原来是因为test_generators.rb使用了Rails :: Generators :: TestCase,后者继承自TestUnit。
由于这个原因,摩卡错误地修补了Test :: Unit而不是MiniTest。解决方案是在test_generators.rb中要求test_helper
并强制MiniTest gem到3.2.0版本。
此提交中的完整解决方案:https://github.com/pokonski/public_activity/commit/731e953068297c7aa6f6f7e2b2251c79843943a1