Created
June 26, 2014 00:13
-
-
Save sentientmonkey/47f767e6708a42ed1776 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "minitest/autorun" | |
| require "date" | |
| class Person | |
| attr_reader :birthday | |
| def initialize(attributes={}) | |
| @birthday = attributes.fetch(:birthday) | |
| end | |
| def can_drink_in?(year) | |
| age_in(year) > 21 | |
| end | |
| def age_in(year) | |
| year - birthday.year | |
| end | |
| def age_now | |
| age_in Date.new.year | |
| end | |
| end | |
| describe Person do | |
| let(:seventy_niner) do | |
| Person.new birthday: Date.new(1979) | |
| end | |
| it "age is determined by their birthday" do | |
| seventy_niner.age_in(2009).must_equal 30 | |
| end | |
| it "can drink if older than 21" do | |
| seventy_niner.can_drink_in?(2009).must_equal true | |
| end | |
| it "age now is today" do | |
| seventy_niner.age_in(Date.new.year).must_equal seventy_niner.age_now | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment