Created
January 5, 2009 03:40
-
-
Save thoughtbot/43254 to your computer and use it in GitHub Desktop.
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
class << Test::Unit::TestCase | |
def context name, &block | |
(@contexts ||= []) << name | |
(@context_blocks ||= []) << block | |
saved_setups = (@context_setups ||= []).dup | |
saved_teardowns = (@context_teardowns ||= []).dup | |
self.instance_eval(&block) | |
@context_setups = saved_setups | |
@context_teardowns = saved_teardowns | |
@contexts.pop | |
@context_blocks.pop | |
end | |
def setup &block | |
@context_setups << block | |
end | |
def teardown &block | |
@context_teardowns << block | |
end | |
def should name, before = nil, &test | |
context_setups = @context_setups.dup | |
context_teardowns = @context_teardowns.dup | |
procs = [context_setups[0..-2], before, context_setups[-1], test, context_teardowns].flatten.compact | |
define_method(["test:", @contexts, "should", name].flatten.join(" ")) do | |
procs.each{|proc| self.instance_eval(&proc) } | |
end | |
end | |
def before_should name, &test | |
should(name, test){ assert true } | |
end | |
def should_eventually name | |
define_method(["test:", @contexts, "should eventually", name].flatten.join(" ")) do | |
STDOUT.print "X" | |
assert true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment