-
-
Save cmorss/2964 to your computer and use it in GitHub Desktop.
undefined
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" | |
class Module | |
alias_method :old_private, :private | |
def private(*args) | |
old_private(*args) | |
end | |
end | |
# More hotness | |
class Mock | |
def explicitly_marked_private; end | |
private :explicitly_marked_private | |
def should_be_public1; end | |
private | |
def after_unqualified_private; end | |
public | |
def should_be_public2; end | |
end | |
class PrivateTest < Test::Unit::TestCase | |
def test_explicitly_marking_something_private_makes_it_private | |
assert(Mock.private_method_defined?(:explicitly_marked_private), | |
"explicitly_marked_private should be private") | |
end | |
def test_method_after_explicit_private_is_still_public | |
assert(Mock.public_method_defined?(:should_be_public1), | |
"should_be_public1 should be public") | |
end | |
def test_method_after_unqualified_private_should_be_private | |
assert(Mock.private_method_defined?(:after_unqualified_private), | |
"after_unqualified_private should be private") | |
end | |
def test_method_after_unqualified_public_is_public_again | |
assert(Mock.public_method_defined?(:should_be_public2), | |
"should_be_public2 should be private") | |
end | |
def test_private_returns_self | |
assert_equal(Mock, Mock.send(:private)) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment