Created
June 10, 2013 03:55
-
-
Save bcardarella/5746455 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 'minitest/autorun' | |
module A; end | |
class Person; end | |
class User | |
prepend A | |
end | |
kode = <<-RUBY_EVAL | |
def tester | |
'It works!' | |
end | |
protected :tester | |
RUBY_EVAL | |
Person.class_eval(kode, __FILE__, __LINE__ + 1) | |
User.class_eval(kode, __FILE__, __LINE__ + 1) | |
describe Person do | |
it 'prints the message' do | |
Person.new.send(:tester).must_equal 'It works!' | |
end | |
end | |
describe User do | |
it 'prints the message' do | |
# won't work because the the top ancestor of the User | |
# receiver is not User. Protected method cannot be accessed | |
User.new.send(:tester).must_equal 'It works!' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment