Created
December 21, 2016 02:51
-
-
Save willnet/20141843b38443e5f67b823ff687f6d5 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 'test/unit' | |
class Person | |
include CheckedAttributes | |
attr_checked :age do |v| | |
v >= 18 | |
end | |
end | |
class TestCheckedAttribute < Test::Unit::TestCase | |
def setup | |
@bob = Person.new | |
end | |
def test_accepts_valid_values | |
@bob.age = 20 | |
assert_equal 20, @bob.age | |
end | |
def test_refuses_invalid_values | |
assert_raises RuntimeError, 'Invalid attribute' do | |
@bob.age = 17 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment