26 lines
837 B
Ruby
26 lines
837 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe PlanetExpressExpress do
|
|
it "calculates the shipment discounts and formats them properly" do
|
|
input_file = File.open(
|
|
File.expand_path("../fixtures/input.txt", __FILE__),
|
|
"r"
|
|
)
|
|
|
|
shipments = PlanetExpressExpress::ShipmentReader.new(PlanetExpressExpress::PRICE_LIST).read_shipments(input_file)
|
|
PlanetExpressExpress::Rules.new(PlanetExpressExpress::PRICE_LIST).apply_rules(shipments)
|
|
PlanetExpressExpress::DiscountBudget.new(PlanetExpressExpress::DISCOUNT_LIMIT).limit_discounts(shipments)
|
|
|
|
output = StringIO.new
|
|
|
|
PlanetExpressExpress::Formatter.new(output).format(shipments)
|
|
|
|
expected_output = File.read(
|
|
File.expand_path("../fixtures/output.txt", __FILE__)
|
|
)
|
|
|
|
output.rewind
|
|
expect(output.read).to match(expected_output)
|
|
end
|
|
end
|