Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Whale question
require 'test/unit'
class Whale
def self.attr_validated(method_name, &validation)
# Enter code here to make all tests pass.
end
attr_validated :num_teeth do |v|
v <= 4
end
end
class TestWhale < Test::Unit::TestCase
def test_good_value
whale = Whale.new
whale.num_teeth = 3
assert_equal 3, whale.num_teeth
end
def test_nil_value
whale = Whale.new
assert_raises ArgumentError do
whale.num_teeth = nil
end
end
def test_illegal_value
whale = Whale.new
assert_raises ArgumentError do
whale.num_teeth = 5
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment