Created
August 11, 2015 04:43
-
-
Save davidbegin/1cfbb18db1d027e700ee to your computer and use it in GitHub Desktop.
Metaprogramming Challenge
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
# CheckedAttributes Challenge | |
# | |
# Make the following two tests pass | |
# only by implementing the module CheckedAttributes | |
class Person | |
include CheckedAttributes | |
attr_checked :age do |v| | |
v >= 18 | |
end | |
end | |
require "minitest/autorun" | |
describe "CheckedAttributes" do | |
before do | |
@subject = Person.new | |
end | |
it "raises an error if the validation fails" do | |
@subject .age = 18 | |
assert_equal @subject .age, 18 | |
end | |
it "raises an error if the validation fails" do | |
assert_raises(CheckedAttributes::ValidationError) { @subject.age = 12 } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment