Created
June 1, 2015 20:48
-
-
Save zachpendleton/e7f1352f4bd079daf288 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
class Widget | |
class << self | |
protected | |
def define_attribute(name) | |
attr_accessor name | |
end | |
end | |
define_attribute :name | |
def initialize(name) | |
@name = name | |
end | |
end |
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" | |
require "minitest/autorun" | |
class WidgetTest < Minitest::Test | |
def setup | |
@subject = Widget.new("foo") | |
end | |
def test_name_is_public | |
assert_equal @subject.name, "foo" # NoMethodError: protected method `name' called for #<Widget:0x7920ba90 @name="foo"> | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment