MiniTest [Rails 4 Countdown to 2013]

Posted on

This post is part of a series of 31 Rails 4 articles being released each day in December 2012.

As of Ruby 1.9, MiniTest has replaced Test::Unit as the testing framework included with the language. Since Rails 4 doesn't support Ruby 1.8, it allowed the team to use MiniTest in the framework moving forward. As of Rails 4, ActiveSupport::TestCase will now subclass MiniTest::Spec, which provides a RSpec-style syntax and contexts to your tests.

Update: ActiveSupport::TestCase will no longer subclass MiniTest::Spec. Moving forward, ActiveSupport::TestCase is subclassing MiniTest::Unit::TestCase. If you are still interested in using the MiniTest spec style, checkout the new gem minitest-spec-rails

RSpec Style Folder Structure

The biggest change being made to testing in Rails 4 is not the swapping of the testing framework, but the testing folder structure. The test folder will have a structure very similar to RSpec:

  • controllers:
  • fixtures
  • helpers
  • integration
  • mailers
  • models

Developers will no longer have to think about if the test is "functional" or a "unit". The structure provides a clear separation of where tests in your application should go.

Further Reading

If you are interested in learning more about what MiniTest has to offer, checkout the following resources:


This post is by Kevin Faustino. Kevin is the Chief Craftsman of Remarkable Labs and also the founder of the Toronto Ruby Brigade.


comments powered by Disqus