Skip to content

Mysterious extra tests when raking?

Usually more tests are a good thing.  However, when you get “extra” tests when you don’t expect them, you might be a little mystified…

rake spec:views
(in /Users/djwonk/dev/ci/cogo/trunk)
………………………………………………………………………………………
Finished in 2.708531 seconds
99 examples, 0 failures
Loaded suite /opt/local/bin/rake
Started
Finished in 0.001315 seconds.
0 tests, 0 assertions, 0 failures, 0 errors

Note how rake spec:views finished… but still goes ahead and runs the suite in /opt/local/bin/rake? In my case the culprit was the ‘html_test’ plugin.  Here’s the first few lines of lib/html_test.rb:

%w(validator assertions url_selector url_checker link_validator validate_filter).each do |file|
  require File.join(File.dirname(__FILE__), file)
end
if RAILS_ENV == ‘test’
  class Test::Unit::TestCase
     include Html::Test::Assertions
  end
  # … 

To fix the problem, I wrapped everything inside the if block:

if RAILS_ENV == ‘test’
  %w(validator assertions url_selector url_checker link_validator validate_filter).each do |file|
     require File.join(File.dirname(__FILE__), file)
  end
  class Test::Unit::TestCase
    include Html::Test::Assertions
  end
  # …

Mystery solved.

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*