when Shipping::OvernightMethod shipping_method.ship_order(self) when Shipping::SameDayMethod shipping_method.ship_order(self) else shipping_method.ship_order(self) end end ... end
} context "when shipping method is a Shipping::RegularMethod" do it "uses Shipping::RegularMethod to ship the order" do allow(shipping_method).to receive(class: Shipping::RegularMethod) subject.ship expect(shipping_method). to have_received_message_chain(:pack, :ship). with(items, seller, buyer) end end context "when shipping method is a Shipping::OvernightMethod" do it "uses Shipping::OvernightMethod to ship the order" do allow(shipping_method).to receive(class: Shipping::OvernightMethod) subject.ship expect(shipping_method). to have_received(:ship_order) end end context "when shipping method is a Shipping::SameDayMethod" do it "uses Shipping::SameDayMethod to ship the order" do allow(shipping_method).to receive(class: Shipping::SameDayMethod) subject.ship expect(shipping_method). to have_received_message_chain(:pack, :send). end end end end
Shipping::OvernightMethod to ship the order" do allow(shipping_method).to receive(class: Shipping::OvernightMethod) subject.ship expect(shipping_method). to have_received(:ship_order) end end
} context "when shipping method is a Shipping::OvernightMethod" do it “ships the order using the given shipping method" do order = Order.new allow(shipping_method).to receive(class: Shipping::OvernightMethod) allow(shipping_method).to receive(:ship_order) { ‘ordered shipped’ } expect(order.ship(shipping_method).to eq ‘ordered shipped’ end end context "when shipping method is a Shipping::SameDayMethod" do it “ships the order using the given shipping method" do order = Order.new allow(shipping_method).to receive(class: Shipping::SameDayMethod) allow(shipping_method).to receive(:ship_order) { ‘ordered shipped’ } expect(order.ship(shipping_method).to eq ‘ordered shipped’ end end context "when shipping method is a different type" do it "uses Shipping::SameDayMethod to ship the order" do allow(shipping_method).to receive(class: nil) subject.ship expect(shipping_method). to have_received_message_chain(:pack, :send). end end end end
} subject { Order.new } it “ships the order using the given shipping method" do order = Order.new.pack allow(shipping_method).to receive(:ship_order) { ‘ordered shipped’ } expect(order.ship(shipping_method).to eq ‘ordered shipped’ end ... end
end it “can be used to ship an order” do order = Order.new shipping_method = subject expect(order).to_not be_shipped order.ship(shipping_method) expect(order).to be_shipped end end
items (except for digital items). • A value that represents the distance between the origin and the destination . • A value that represents a fixed rate. items_quantity * distance * fixed_rate
origin, destination) } context "when all items in the order are digital" do ... end context "when exactly one item in the order is not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when more than one item in the order are not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when origin city doesn't ship to the destination" do ... end end ... end
def calculate items_quantity * rate * distance end ... private def items_quantity @order.items.reject(:digital?).lenght end def rate if items_quantity > 1 9.99 else 5.99 end end def distance return 0 if @origin.does_not_ship_to? @destination return 1 if @origin.same_state? @destination return 2 if @origin.same_country? @destination 3 end end end
origin, destination) } context "when all items in the order are digital" do ... end context "when exactly one item in the order is not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when more than one item in the order are not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when the origin city doesn't ship to the destination" do ... end end ... end
origin, destination) } context "when all items in the order are digital" do ... end context "when exactly one item in the order is not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when more than one item in the order are not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when the origin city doesn't ship to the destination" do ... end end ... end
in the order are digital" do ... end context "when exactly one item in the order is not digital" do ... end context "when more than one item in the order are not digital" do ... end end end
origin, destination) } context "when all items in the order are digital" do ... end context "when exactly one item in the order is not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when more than one item in the order are not digital" do context "when the origin and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end end context "when the origin city doesn't ship to the destination" do ... end end ... end
state” • "when the origin and destination are in the same country” • "when the origin and destination are in different countries” • "when the origin city doesn't ship to the destination"
and destination are in the same state" do ... end context "when the origin and destination are in the same country" do ... end context "when the origin and destination are in different countries" do ... end context "when the origin city doesn't ship to the destination" do ... end end end
def calculate items_quantity * rate * distance end private def items_quantity Shipping::Items.new(@order).quantity end def rate if items_quantity > 1 9.99 else 5.99 end end def distance Shipping::Distance.new(origin, destination).calculate end end end
def calculate items_quantity * rate * distance end private def items_quantity Shipping::Items.new(@order).quantity end def rate Shipping::Rate.new(items_quantity).calculate end def distance Shipping::Distance.new(origin, destination).calculate end end end