The spec library in Minitest is great. I've been able to use it within Rails unit tests no problem. However, Rails functional test inherit from ActionController::TestCase which provides instance variables like @controller in it's setup.
Has anyone been using the Minitest::Spec lib for their Rails functional tests?
If not, I'm considering creating a small library to do just that. I'm not too keen on rspec, and shoulda is starting to shift it's focus to rspec. It would be nice to have something lightweight and built on tools already provided.
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.
We can run all of our tests at once by using the bin/rails test command. 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.
They make sure that a section of an application, or a “unit”, is behaving as intended. 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.
Thoughtbot have now split shoulda into shoulda_contexts and shoulda_matchers so the worry about a shift to rspec for thoughtbot doesn't mean shoulda contexts are going away. Just being maintained in the community.
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