Created
October 12, 2009 13:40
-
-
Save gotascii/208389 to your computer and use it in GitHub Desktop.
This file contains 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
require 'test/unit' | |
require 'shoulda' | |
class Test::Unit::TestCase | |
def self.context_helper(helper_arg, &block) | |
context "context helper #{helper_arg}" do | |
setup do | |
@helper_arg = helper_arg | |
end | |
merge_block(&block) if block_given? | |
end | |
end | |
end | |
class SpecificTestCase < Test::Unit::TestCase | |
context "An outter context" do | |
setup do | |
# @setup_var defined in a block which is called | |
# when the test is run, inside a test instance scope. | |
@setup_var = "not available in class scope" | |
end | |
# @setup_var is defined here as an argument to the | |
# class method context_helper, in the class scope. | |
# This is a different variable from the @setup_var | |
# defined in the setup block. At this point the | |
# setup block has yet to be executed, so the | |
# variable in the setup block has not been defined. | |
context_helper(@setup_var) do | |
should "be false" do | |
assert_not_equal @setup_var, @helper_arg | |
end | |
should "be nil" do | |
assert @helper_arg.nil? | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment