开发者

Why is "rake tests" running an empty suite when I use shoulda?

So here is my test suite:

class ReleaseTest < ActiveSupport::TestCase
  should_not_allow_values_for :title, '', 'blah', 'blah  blah'
  should_allow_values_for :title, 'blah - bleh', 'blah blah - bleh bleh'
  def test_something
    assert true
  end
end

Shoulda's macros generate 5 tests, and then I have test_something below (just to see if that would matter), totalling 6 tests. They all pass as you can see below, but then it runs a 0-test suite. This happens even if I completely empty out ReleaseTest. This problem only exists if I have config.gem 'shoulda' in my environment.rb. If I explicitly do require 'shoulda' at the top of my tests, everything works fine. What would be causing this?

/usr/bin/ruby -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) /var/lib/gems/1.9.1/bin/rake test
Testing started at 6:58 PM ...
(in /home/rlepidi/projects/rails/testproject)
/usr/bin/ruby1.9.1 -I"lib:test" "/var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/release_test.rb" 

Loaded suite /var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
......
Finished in 0.029335778 seconds.
6 tests, 6 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

/usr/bin/ruby1.9.1 -I"lib:test" "/var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"  
/usr/bin/ruby1.9.1 -I"lib:test" "/var/lib/gems/1.9.1/gems/rake-0.8.7/lib/rake/rake_test_loader.rb"  

Loaded suite /var/lib/gems/1.9.1/bin/r开发者_如何学运维ake
Started
Finished in 0.000106717 seconds.
0 tests, 0 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
0% passed
Empty test suite.


The problem, for some reason, was that I needed to install test-unit since I am running Ruby 1.9. I've heard that this is because Test::Unit is no longer included in 1.9, but I don't understand that because it looks like my tests were still running correctly (and I didn't have that gem installed).


In case anyone else is having this problem:

I had this problem happen because I was using the assert2 gem. See my blog post "Why I stopped using assert{ 2.0 }". Installing test-unit didn't solve the problem for me; I ended up removing assert2 from my Gemfile instead.

Edit: Apparently Minitest's Test::Unit wrapper (and presumably the original Test::Unit) automatically installs an exit handler to run the tests. (Icky, isn't it? ;-)) So this "empty test suite" problem might pop up in any situation where the exit handler got registered accidentally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜