1

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!

fearless_fool
  • 33,645
  • 23
  • 135
  • 217

1 Answers1

3

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
DAddYE
  • 1,719
  • 11
  • 16
  • Really great -- I've switched over to Guard and I'm liking it. Do you happen to use growl or ruby_gntp, and do you use spork? I'm trying to decide which notifier to use... – fearless_fool Mar 24 '13 at 06:17
  • In my enthusiasm, I checked your answer. But to be true to the original question, the answer needs to show what you have in your test_helper file, and perhaps test.rake or whatever makes minitest go. Add that and I'll give you your check back!! – fearless_fool Mar 24 '13 at 06:24
  • Okay, added it. Remember that I usually name it helper.rb and not test_helper.rb or helper_test.rb – DAddYE Mar 24 '13 at 15:58
  • Fair 'nuff. I assume you're extending MiniTest::Unit::TestCase somewhere else (don't you have do define #app)? – fearless_fool Mar 25 '13 at 06:08