0

I have two questions. The first is a basic one. MiniTest is a drop-in replacement for UnitTest. So if you use generators in rails, you get a bunch of ActiveSupport::TestCase classes. If you use minitest (without minitest-spec-rails) then you can do

1.must_equal 1
# instead of 
assert_equal 1, 1

Correct? So it's confusing to me why there's a MiniTest::Unit::TestCase class as described in railscast #327 (pro episode paywall sry). It's confusing when looking at a test suite which I'm actually using. If minitest is a drop-in replacement then I'm using minitest to execute testunit style rails tests. If I take it out, I'm using testunit to run testunit tests?

So let's say I am using MiniTest to run TestUnit style tests.

require 'test_helper'
class FooTest < ActiveSupport::TestCase
end

After watching destroyallsoftware's screencast on extracting domain objects, I was inspired. He makes some good points about avoiding loading test_helper.rb to speed up the test suite without resorting to spork trickery (which is exactly what I do). But how can I avoid loading test_helper.rb when that's what gives me ActiveSupport::TestCase from above?

Can you not extract domain objects and put them in lib/ or extras/ with MiniTest or TestUnit?

squarism
  • 3,242
  • 4
  • 26
  • 35

1 Answers1

2

The answer to your first question is "no, not correct". Minitest is not a "drop-in replacement" for Test::Unit. Minitest provides a simpler implementation for most of Test::Unit, but not all of it. In Ruby 1.9 the Test::Unit library is built on top of Minitest's TestCase class, and fills the gaps between the two libraries.

Minitest provides two modes for writing tests: the classic TestCase approach, and a separate Spec DSL. Like Test::Unit, the Spec DSL is built on top of Minitest's TestCase. So while 1.9's Test::Unit and Minitest's Spec DSL are both are built on Minitest's TestCase, you can't use the Spec DSL in Test::Unit because its not part of its ancestry.

The answer to your second question is you cannot avoid test_helper.rb if you want to use ActiveSupport::TestCase. You will need to require minitest/autorun and have your test class inherit from MiniTest::Unit::TestCase.

blowmage
  • 8,854
  • 2
  • 35
  • 40