Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Square job interview exercise
class Payment
def initialize(amount)
@amount = amount
end
def fee_amount
case @amount.round
when 10 then 0.44
when 42 then 1.37
else
raise ArgumentError, "There is no specification for the fee amount that should be added when the payment amount is `#{@amount}'."
end
end
end
describe Payment, "#fee_amount" do
it "returns 2.9% of $10 + $0.15 ($0.44)" do
payment = Payment.new(10.00)
payment.fee_amount.should == 0.44
end
it "returns 2.9% of $42 + $0.15 ($1.37)" do
payment = Payment.new(42.00)
payment.fee_amount.should == 1.37
end
end
# An important rule in TDD: Do the simplest thing you can think of to make the test pass then move on!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment