Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

ruby tests for visitor pattern blog post

View visitor_pattern_tests_ruby_20081130_blogpost.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
require ‘ruby.visitor’
describe EmployeePaycheckVisitor do
before do
@visitor = EmployeePaycheckVisitor.new
end
it “should generate hourly report for hourly employee” do
@jason = HourlyEmployee.new(“Jason”, 55.00)
@jason.addHoursWorked(120)
@jason.addSickDaysUsed(1)
@jason.addVacationDaysUsed(2)
@jason.accept(@visitor)
@visitor.earnedWages.should == 6160.0
@visitor.sickDayDeductions.should == 440.0
@visitor.paycheckInfo.should ==Hourly employee Jason worked 120 hours, ” +
“earned $6160.00 with 1 sick day(s) ($440.00 deducted) and 2 vacation day(s)”
end
it “should generate salaried report for salaried employee” do
@john = FulltimeEmployee.new(“John”, 58000)
@john.addBusinessDaysWorked(120)
@john.addSickDaysUsed(3)
@john.addVacationDaysUsed(5)
@john.accept(@visitor)
@visitor.earnedWages.should == 26091
@visitor.sickDayDeductions.should == 669
@visitor.paycheckInfo.should ==Fulltime employee John worked 120 business days, ” +
“earned $26091.00 with 3 sick day(s) ($669.00 deducted) and 5 vacation day(s)”
end
end
 
require ‘ruby.visitor’
describe EmployeePaycheckVisitor do
before do
@visitor = EmployeePaycheckVisitor.new
end
it “should generate hourly report for hourly employee” do
@jason = HourlyEmployee.new(“Jason”, 55.00)
@jason.addHoursWorked(120)
@jason.addSickDaysUsed(1)
@jason.addVacationDaysUsed(2)
@jason.accept(@visitor)
@visitor.earnedWages.should == 6160.0
@visitor.sickDayDeductions.should == 440.0
@visitor.paycheckInfo.should ==Hourly employee Jason worked 120 hours, ” +
“earned $6160.00 with 1 sick day(s) ($440.00 deducted) and 2 vacation day(s)”
end
it “should generate salaried report for salaried employee” do
@john = FulltimeEmployee.new(“John”, 58000)
@john.addBusinessDaysWorked(120)
@john.addSickDaysUsed(3)
@john.addVacationDaysUsed(5)
@john.accept(@visitor)
@visitor.earnedWages.should == 26091
@visitor.sickDayDeductions.should == 669
@visitor.paycheckInfo.should ==Fulltime employee John worked 120 business days, ” +
“earned $26091.00 with 3 sick day(s) ($669.00 deducted) and 5 vacation day(s)”
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.