Created
October 11, 2020 00:46
-
-
Save sumeet/afc369cc467757ea64a38078f59fb678 to your computer and use it in GitHub Desktop.
another masterpiece, idiomatic ruby converting one test type to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def describe(name, &block) | |
klass = Class.new(Bridge, &block) | |
Object.const_set(name + "Test", klass) | |
end | |
class Bridge < Minitest::Test | |
def self.before(range, &block) | |
define_method("before_#{range}") do |*args| | |
instance_eval(&block) | |
super *args | |
end | |
end | |
def self.after(range, &block) | |
define_method("after_#{range}") do |*args| | |
instance_eval(&block) | |
super *args | |
end | |
end | |
def self.it(name, &block) | |
define_method("test_" + name.split(" ").join("_"), &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment