Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ruby tests for visitor pattern blog post
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.