Skip to content

Instantly share code, notes, and snippets.

@zachpendleton
Created June 1, 2015 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachpendleton/e7f1352f4bd079daf288 to your computer and use it in GitHub Desktop.
Save zachpendleton/e7f1352f4bd079daf288 to your computer and use it in GitHub Desktop.
class Widget
class << self
protected
def define_attribute(name)
attr_accessor name
end
end
define_attribute :name
def initialize(name)
@name = name
end
end
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