Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created July 23, 2011 20:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/1101844 to your computer and use it in GitHub Desktop.
Save tenderlove/1101844 to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
class MyTest < MiniTest::Unit::TestCase
class SomeClass
def calls_takes_args
takes_args "hello world"
end
private
def takes_args arg
puts "i was called"
end
end
def setup
#pretend this instance came from somewhere else
@instance = SomeClass.new
end
def test_immediate_check_args
tc = self
@instance.extend Module.new {
define_method(:takes_args) { |arg|
tc.assert_equal 'hello world', arg
super(arg)
}
}
@instance.calls_takes_args
end
def test_check_args_later
args = []
@instance.extend Module.new {
define_method(:takes_args) { |arg|
args << arg
super(arg)
}
}
@instance.calls_takes_args
assert_equal ['hello world'], args
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment