Some utilities for your Minitest day-to-day usage.
Includes:
- A better reporter (see screenshot below)
- A TestNotifier reporter
- Some Rails niceties (set up FactoryGirl, WebMock and Capybara)
- Add a
tandlmethods (i18n)
Add this line to your application's Gemfile:
gem 'minitest-utils'And then execute:
$ bundle
Or install it yourself as:
$ gem install minitest-utils
This gem adds the Minitest::Test.test method, so you can easy define your methods like the following:
class SampleTest < Minitest::Test
test 'useless test' do
assert true
end
endThis is equivalent to defining a method named test_useless_test. You can also skip the block, which will define a flunk call.
You can also define setup and teardown steps.
class SampleTest < Minitest::Test
setup do
DB.connect
end
teardown do
DB.disconnect
end
test 'useless test' do
assert true
end
endFinally, you can also use let.
class SampleTest < Minitest::Test
let(:token) { 'secret' }
test 'set token' do
assert_equal 'secret', token
end
endminitest-utils sets up some things for your Rails application.
- Capybara: includes
Capybara::DSL, sets default driver before every test, resets session and creates a helper method for setting JavaScript driver. If you have poltergeist installed, it will be used as the default JavaScript driver. - FactoryGirl: adds methods to
ActiveSupport::TestCase. - WebMock: disables external requests (except for codeclimate) and tracks all requests on
WebMock.requests. - locale routes: sets
Rails.application.routes.default_url_options[:locale]with your current locale. - DatabaseCleaner: configure database before running each test. You can configure the strategy by settings
DatabaseCleaner.strategy = :truncation, for instance. It defaults to:deletion. - Other:
tandlalias to I18n.
class SignupTest < ActionDispatch::IntegrationTtest
use_javascript! #=> enables JavaScript driver
endAlso, if you're using routes like :locale scope, you can load this file to automatically set your route's :locale param.
require 'minitest/utils/rails/locale'After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
- Fork it ( https://github.com/fnando/minitest-utils/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request



