Skip to content

Instantly share code, notes, and snippets.

@ClayShentrup
Created July 20, 2012 05:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClayShentrup/3148813 to your computer and use it in GitHub Desktop.
Save ClayShentrup/3148813 to your computer and use it in GitHub Desktop.
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