Skip to content

Commit

Permalink
* Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledestin committed Aug 17, 2014
1 parent 24957ac commit 86bc449
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions spec/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@
require "./lib/item"

module FakeTaxRates
def self.tax_rate_for_good name
def self.tax_rate_for_good(name)
0.1
end
end

Item = ShoppingCart::Item

describe Item do
describe "#tax returns amount of tax for the good:" do
describe "#tax returns amount of tax for the item:" do
it "10% for item" do
good = Item.new 1, "item", 10.0, tax_rates: FakeTaxRates
expect(good.tax).to eq 1
item = Item.new 1, "item", 10, tax_rates: FakeTaxRates
expect(item.tax).to eq 1
end

it "double for 2 items" do
good = Item.new 2, "item", 10, tax_rates: FakeTaxRates
expect(good.tax).to eq 2
item = Item.new 2, "item", 10, tax_rates: FakeTaxRates
expect(item.tax).to eq 2
end

it "rounded up to the nearest 0.05" do
good = Item.new 1, "item", 47.30, tax_rates: FakeTaxRates
expect(good.tax).to eq 4.75
item = Item.new 1, "item", 47.30, tax_rates: FakeTaxRates
expect(item.tax).to eq 4.75
end
end

describe "#total returns unit_price + tax, multiplied by quantity" do
describe "#total returns total cost of items, including tax:" do
it "one item" do
good = Item.new 1, "item", 10.0, tax_rates: FakeTaxRates
expect(good.total).to eq 11
item = Item.new 1, "item", 10, tax_rates: FakeTaxRates
expect(item.total).to eq 11
end

it "two items" do
good = Item.new 2, "item", 10.0, tax_rates: FakeTaxRates
expect(good.total).to eq 22
item = Item.new 2, "item", 10.0, tax_rates: FakeTaxRates
expect(item.total).to eq 22
end
end

it "#to_s returns quantity, name and total" do
good = Item.new 2, "item", 10.0, tax_rates: FakeTaxRates
expect(good.to_s).to eq "2, item, 22.00"
item = Item.new 2, "item", 10, tax_rates: FakeTaxRates
expect(item.to_s).to eq "2, item, 22.00"
end
end

0 comments on commit 86bc449

Please sign in to comment.