Skip to content
Michael Mahemoff edited this page Mar 25, 2015 · 5 revisions

Tapout on Rails

Installation

To begin, add Tapy to your Gemfile's test group:

group :test do
    gem 'minitap'
    gem 'tapout'
end

If you've previously installed other tools such as turn and minitest-reporters, remove them from your Gemfile and remove references to them in test/test_helper.rb.

Then run bundle.

Try it on a single test

RAILS_ENV=test bundle exec ruby test/models/user_test.rb --tapy | bundle exec tapout progress

Bit of a mouthful huh? You could alias that in ~/.bash_profile:

function tap {
  # can use progress, outline, pretty, turn ...
  RAILS_ENV=test bundle exec ruby $* --tapy | bundle exec tapout pretty
}

Then you can run, for example, tap test/models/user_test.rb or tap test/models/user_test.rb -n /login/.

Add a Rake task

Rails provides a set of Rake tasks for testing. While Rails::TestTask is a subclass on Rake::TestTask, it does not shell-out for testing like the Rake test task can, therefore adding a pipe to TESTOPTS will not work.

One work around for this, offered up by @abinoam, is to shell-out the Rails Rake task.

desc "Run 'rake test' through tapout"
task :tapout, [:reporter] do |t, args|
  reporter = args.reporter || "runtime"
  sh "RAILS_ENV='test' TESTOPTS='- --tapy' bin/rake -q test | tapout #{reporter}"
end

With this one can run rake tapout to run all tests. Or even rake tapout[outline] to select the output reporter.