Skip to content

Instantly share code, notes, and snippets.

@nesquena
Created November 30, 2011 21:03
Show Gist options
  • Save nesquena/1410808 to your computer and use it in GitHub Desktop.
Save nesquena/1410808 to your computer and use it in GitHub Desktop.
Setup Minitest in a Gem

Minitest Steps

Add to gemspec:

# my_gem.gemspec

Gem::Specification.new do |s|
  # ...
  
  s.add_development_dependency 'minitest', "~> 2.6.1"
  s.add_development_dependency 'rake'
  s.add_development_dependency 'mocha'
  s.add_development_dependency 'fakeweb'
end

add a test_helper:

# test/test_helper.rb

ENV["TEST"] = 'true'
require 'rubygems'
require 'minitest/autorun'
$:.unshift File.expand_path("../../lib")
require 'mygem'
require 'fakeweb'
require 'mocha'

FakeWeb.allow_net_connect = false

and a test file:

# test/configuration_test.rb

require File.expand_path('../test_helper', __FILE__)

describe "configuration" do
  before do
    # ...
  end


  it "does something" do
    # ...
  end
end

and to Rakefile:

require 'rake/testtask'

Rake::TestTask.new do |t|
  t.libs.push "lib"
  t.test_files = FileList[File.expand_path('../test/**/*_test.rb', __FILE__)]
  t.verbose = true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment