Skip to content

Instantly share code, notes, and snippets.

@nysalor
Created July 27, 2012 11:19
Show Gist options
  • Save nysalor/3187454 to your computer and use it in GitHub Desktop.
Save nysalor/3187454 to your computer and use it in GitHub Desktop.
TDD sample
# -*- coding: utf-8 -*-
require './age_calc'
require 'date'
describe AgeCalc do
before do
@age_calc = AgeCalc.new
end
it "birthdayで誕生日が設定できること" do
@age_calc.birthday = Date.new(1989,2,25)
@age_calc.birthday.should == Date.new(1989,2,25)
end
it "ageで年齢が返ること" do
@age_calc.birthday = Date.new(1989,2,25)
@age_calc.age.should == 23
end
it "birthdayが未設定の場合、ageでnilが返ること" do
@age_calc.age.should be_nil
end
it "birthdayにDate以外の値を設定すると、ageで例外が返ること" do
@age_calc.birthday = "23 years ago"
lambda{@age_calc.age}.should raise_error
end
it "increment_ageでageが1増えること" do
@age_calc.birthday = Date.new(1989,2,25)
lambda {@age_calc.increment_age}.should change(@age_calc, :age).from(23).to(24)
end
it "ageが20から30の間にあること" do
@age_calc.birthday = Date.new(1989,2,25)
@age_calc.age.should be_close(20,30)
end
it "yearsが空になること" do
@age_calc.years.should be_empty
end
it "ageがDateクラスのオブジェクトでないこと" do
@age_calc.birthday = Date.new(1989,2,25)
@age_calc.age.should_not be_is_a(Date)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment