Skip to content

Instantly share code, notes, and snippets.

@nesquena
Created September 3, 2011 13:34
Show Gist options
  • Save nesquena/1191186 to your computer and use it in GitHub Desktop.
Save nesquena/1191186 to your computer and use it in GitHub Desktop.
MiniTest + Shoulda Compatibility
# http://metaskills.net/2011/01/25/from-test-unit-shoulda-to-minitest-spec-minishoulda/
# Gives you all the the stuff to make existing shoulda tests work!
class MiniTest::Spec
class << self
alias :setup :before unless defined?(Rails)
alias :teardown :after unless defined?(Rails)
alias :should :it
alias :context :describe
end
alias :assert_no_match :refute_match
alias :assert_not_nil :refute_nil
alias :assert_not_equal :refute_equal
def assert_nothing_raised(&block)
block.call # this assertion no longer exists!
end
def self.should_eventually(desc)
it("should eventually #{desc}") { skip("Should eventually #{desc}") }
end
end

These are replacements I did in my project to go from test/unit + shoulda to minitest + mini_shoulda.rb (above)

  • assert_raise => assert_raises
  • class Test(.*?) < Test::Unit::TestCase => describe "$1" do
  • require 'test/unit' => require 'minitest/spec'
  • require 'shoulda' => require 'minitest/autorun'
  • class Test::Unit::TestCase => class MiniTest::Spec
  • Test::Unit::Assertions => MiniTest::Assertions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment