Search code examples
rubyguardminitestautotestgrowl

a concise recipe for installing, configuring and running minitest under autotest or Guard


In the past, I've run Rails + RSpec + autotest. Now I've upgraded to ruby 2.0 and I want to use minitest in a non-Rails environment (I'm using Padrino / DataMapper). I'm certain I'm not alone in wanting this.

What would be really useful is a concise recipe for installing and configuring things so the simple command:

$ autotest

or

$ bundle exec guard

will start testing everything under /test. I have searched SO and the InterWebs, and have yet to find such a recipe. A recipe should include:

  • what gems should you include in your Gemfile?
  • what commands do you run to set up the environment?
  • what configuration and support files do you need to create (Rakefile? .autotest? etc...)
  • a means for test files to require 'test_helper' to take care of repetitive functions

Extra credit for showing how to configure growl and spork for the full-on XP experience!


Solution

  • Mmm, I don't use autotest, nowadays seems that Guard is best fit, so:

    # Add to Gemfile
    group :development do
      gem 'terminal-notifier-guard'    # or libnotify for linux
      gem 'rb-fsevent', require: false # or rb-inotify for linux
      gem 'guard-minitest'
      gem 'minitest'
    end
    
    # From bash
    $ bundle update
    $ guard init minitest # or bundle exec guard init minitest
    
    # Edit the GuardFile, mine looks like:
    guard 'minitest' do
      # with Minitest::Unit
      watch(%r|^test/(.*)\/?test_(.*)\.rb|)
      watch(%r|^app/models/(.*)\.rb|)  { |m| "test/test_#{m[1]}.rb" }
      watch(%r|^lib/(.*)([^/]+)\.rb|)  { |m| "test/test_#{m[2]}.rb" }
      watch(%r|^test/helper\.rb|)      { 'test' }
    end
    
    # Here my test helper.rb. /test/helper.rb
    ENV['PADRINO_ENV'] ||= 'test'
    require_relative '../config/boot'
    require 'minitest/autorun'
    
    
    # Have fun!
    $ bundle exec guard