Skip to content

Instantly share code, notes, and snippets.

@ntl
Created June 27, 2015 02:27
Show Gist options
  • Save ntl/470004c48b5fc2422ec7 to your computer and use it in GitHub Desktop.
Save ntl/470004c48b5fc2422ec7 to your computer and use it in GitHub Desktop.
source "https://rubygems.org"
gem "whatever"
# Load minitest and red-green
group :minitest do
gem "minitest"
gem "minitest-rg"
end
#!/usr/bin/env ruby
# Put this in bin/run_tests.rb or something and chmod 755 it
# Load bundler
require "bundler/setup"
Bundler.require :default, :minitest
# Load your code
require_relative "../lib/my_gem.rb"
# Run minitest with ARGV
Dir["tests/**/*.rb"].each &method(:load)
Minitest.run ARGV
@ntl
Copy link
Author

ntl commented Jun 27, 2015

The key learning before this setup works is twofold:

  1. If your test suite is fast, you generally want to run the whole test suite all the time. Sometimes you need to focus on a single test, but you can do that with the arguments you pass into Minitest.run
  2. You don't actually want any test setup, support, or environment code. This means to test/test_helper.rb, no test/support/*, etc. If you need sample data, stick it in a directory called sample_data and write a loader class for it. Bundle that loader class in with your library, it'll actually help people actually exercise your code.

Writing test suites like this, with no fluff around them, helps the TDD process by forcing you to feel maximum pain when your objects are difficult to demonstrate via exercising simple examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment