I read somewhere that 'minitest' is the "new test::unit for ruby 1.9.2+".
But ruby 1.9.3 seems to include both test::unit and minitest, is that true?
In the default rails testing, as outlined in the Rails testing guide.... things like ActiveSupport::TestCase
, ActionController::TestCase
, are these using Test::Unit
or Minitest
?
In the rails guide, it shows examples with tests defined like this:
test "should show post" do get :show, :id => @post.id assert_response :success end
That syntax, test string
, as opposed to defining methods with names like test_something
-- isn't mentioned in the docs for either Test::Unit
or Minitest. Where's that coming from? Is Rails adding it, or is it actually a part of... whatever testing lib rails is using?
PS: Please don't tell me "just use rspec". I know about rspec. I am trying to explore the stdlib alternatives, in the context of rails.
To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.
In a Rails context, unit tests are what you use to test your models. Although it is possible in Rails to run all tests simultaneously, each unit test case should be tested independently to isolate issues that may arise.
Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.
There is a Test::Unit
"compatibility" module that comes with Minitest, so that you can (presumably) use your existing Test::Unit tests as-is. This is probably the Test::Unit
module you are seeing.
As of rails 3.2.3, generator-created tests include rails/test_help
which includes test/unit
.
The test "something" do
syntax is a rails extension. It's defined in ActiveSupport::Testing::Declarative
, which is require
'd by rails/test_help
.
This is perhaps a bit of a tangential response, but as to your rspec comment... You might want to take a look at minitest/spec
which provides spec flavor syntax in stdlib in 1.9.x.
http://bfts.rubyforge.org/minitest/MiniTest/Spec.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With