Skip to content

Instantly share code, notes, and snippets.

@webmat
Last active December 11, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webmat/4607174 to your computer and use it in GitHub Desktop.
Save webmat/4607174 to your computer and use it in GitHub Desktop.
Missing Rails-style declarative helpers in your plain minitest/unit test suite? Here's something to get you started.
class MiniTest::Unit::TestCase
class << self # The def self.test way of doing it doesn't override Kernel.test but this does...
def test(name, &block)
method_name = "test_#{ name.gsub(/[\W]/, '_') }"
if block.nil?
define_method(method_name) do
flunk "Missing implementation for test #{name.inspect}"
end
else
define_method(method_name, &block)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment