Skip to content

Instantly share code, notes, and snippets.

@martincharlesworth
Last active January 3, 2016 08:29
Show Gist options
  • Save martincharlesworth/8436793 to your computer and use it in GitHub Desktop.
Save martincharlesworth/8436793 to your computer and use it in GitHub Desktop.
ruby testing with minitest

Testing a gem with minitest

Add test dir to gem's root

mkdir test

Create test/test_helper.rb

require 'simplecov'
SimpleCov.start

require <gem_name>

require "minitest/autorun"
require "minitest/pride"

Create Rakefile

require "bundler/gem_tasks"
require 'rake/testtask'

Rake::TestTask.new do |t|
  t.libs << "test"
  t.pattern = "test/*_test.rb"
end

Create test files

require "test_helper"

class <gem_name>Test < Minitest::Test
  def setup
  end

  def test_something
    assert_equal true, foo
  end
  
  def teardown
  end
end

Run all tests

rake test

Running a single test method

ruby -Ilib:test <test_file> -n <test_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment