Created
December 15, 2010 05:44
-
-
Save dchelimsky/741672 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 'matchers.rb' | |
describe CheckOut do | |
let(:checkout) { CheckOut.new(RULES) } | |
context "calculating totals" do | |
subject { checkout } | |
it { should price("").at(0) } | |
it { should price("A").at(50) } | |
it { should price("AB").at(80) } | |
it { should price("CDBA").at(115) } | |
it { should price("AA").at(100) } | |
it { should price("AAA").at(130) } | |
it { should price("AAAA").at(180) } | |
it { should price("AAAAA").at(230) } | |
it { should price("AAAAAA").at(260) } | |
it { should price("AAAB").at(160) } | |
it { should price("AAABB").at(175) } | |
it { should price("AAABBD").at(190) } | |
it { should price("DABABA").at(190) } | |
end | |
it "calculates incremental totals" do | |
checkout.total.should eq(0) | |
checkout.scan("A"); checkout.total.should eq(50) | |
checkout.scan("B"); checkout.total.should eq(80) | |
checkout.scan("A"); checkout.total.should eq(130) | |
checkout.scan("A"); checkout.total.should eq(160) | |
checkout.scan("B"); checkout.total.should eq(175) | |
end | |
end |
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
RSpec::Matchers.define :price do |goods| | |
match do |checkout| | |
goods.split(//).each { |item| checkout.scan(item) } | |
(@actual_total = checkout.total) == @price | |
end | |
chain :at do |price| | |
@price = price | |
end | |
failure_message_for_should do |checkout| | |
"expected checkout to price #{goods.inspect} at #{@price}, got #{@actual_total}" | |
end | |
description do | |
"price #{goods.inspect} at #{@price}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment