Skip to content

Instantly share code, notes, and snippets.

@willnet
Last active December 14, 2016 04:45
Show Gist options
  • Select an option

  • Save willnet/8a38602cdac6ba20c18693403aea7320 to your computer and use it in GitHub Desktop.

Select an option

Save willnet/8a38602cdac6ba20c18693403aea7320 to your computer and use it in GitHub Desktop.
require 'test/unit'
class Person; end
class TestCheckedAttribute < Test::Unit::TestCase
def setup
add_checked_attribute(Person, :age)
@bob = Person.new
end
def test_accepts_valid_values
@bob.age = 20
assert_equal 20, @bob.age
end
def test_refuses_nil_values
assert_raises RuntimeError, 'Invalid attribute' do
@bob.age = nil
end
end
def test_refuses_false_values
assert_raises RuntimeError, 'Inlalid attribute' do
@bob.age = false
end
end
def add_checked_attribute(klass, attribute)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment