From ec069b1e3ecbe23ea5daf179ff8bb49be394b324 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 13 Aug 2018 16:13:02 +0100 Subject: [PATCH] Converted specs to latest rspec syntax --- spec/controllers/cart_controller_spec.rb | 54 +++--- .../spree/orders_controller_spec.rb | 44 ++--- spec/services/cart_service_spec.rb | 172 +++++++++--------- 3 files changed, 137 insertions(+), 133 deletions(-) diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb index 4345b91a52..4164cbddba 100644 --- a/spec/controllers/cart_controller_spec.rb +++ b/spec/controllers/cart_controller_spec.rb @@ -7,16 +7,16 @@ describe CartController, type: :controller do let(:product) { create(:simple_product) } it "returns stock levels as JSON" do - controller.stub(:variant_ids_in) { [123] } - controller.stub(:stock_levels) { 'my_stock_levels' } - CartService.stub(:new).and_return(cart_service = double()) - cart_service.stub(:populate) { true } - cart_service.stub(:variants_h) { {} } + allow(controller).to receive(:variant_ids_in) { [123] } + allow(controller).to receive(:stock_levels) { 'my_stock_levels' } + allow(CartService).to receive(:new).and_return(cart_service = double()) + allow(cart_service).to receive(:populate) { true } + allow(cart_service).to receive(:variants_h) { {} } xhr :post, :populate, use_route: :spree, format: :json data = JSON.parse(response.body) - data['stock_levels'].should == 'my_stock_levels' + expect(data['stock_levels']).to eq('my_stock_levels') end describe "generating stock levels" do @@ -27,31 +27,35 @@ describe CartController, type: :controller do before do order.reload - controller.stub(:current_order) { order } + allow(controller).to receive(:current_order) { order } end it "returns a hash with variant id, quantity, max_quantity and stock on hand" do - controller.stock_levels(order, [v.id]).should == + expect(controller.stock_levels(order, [v.id])).to eq( {v.id => {quantity: 2, max_quantity: 3, on_hand: 4}} + ) end it "includes all line items, even when the variant_id is not specified" do - controller.stock_levels(order, []).should == + expect(controller.stock_levels(order, [])).to eq( {v.id => {quantity: 2, max_quantity: 3, on_hand: 4}} + ) end it "includes an empty quantity entry for variants that aren't in the order" do - controller.stock_levels(order, [v.id, v2.id]).should == + expect(controller.stock_levels(order, [v.id, v2.id])).to eq( {v.id => {quantity: 2, max_quantity: 3, on_hand: 4}, v2.id => {quantity: 0, max_quantity: 0, on_hand: 2}} + ) end describe "encoding Infinity" do let!(:v) { create(:variant, on_demand: true, count_on_hand: 0) } it "encodes Infinity as a large, finite integer" do - controller.stock_levels(order, [v.id]).should == + expect(controller.stock_levels(order, [v.id])).to eq( {v.id => {quantity: 2, max_quantity: 3, on_hand: 2147483647}} + ) end end end @@ -60,7 +64,7 @@ describe CartController, type: :controller do variants_h = [{:variant_id=>"900", :quantity=>2, :max_quantity=>nil}, {:variant_id=>"940", :quantity=>3, :max_quantity=>3}] - controller.variant_ids_in(variants_h).should == [900, 940] + expect(controller.variant_ids_in(variants_h)).to eq([900, 940]) end end @@ -70,33 +74,33 @@ describe CartController, type: :controller do p = create(:product, :distributors => [distributor_product], :group_buy => true) order = subject.current_order(true) - order.stub(:distributor) { distributor_product } - order.should_receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) - controller.stub(:current_order).and_return(order) + allow(order).to receive(:distributor) { distributor_product } + expect(order).to receive(:set_variant_attributes).with(p.master, {'max_quantity' => '3'}) + allow(controller).to receive(:current_order).and_return(order) expect do - spree_post :populate, :variants => {p.master.id => 1}, :variant_attributes => {p.master.id => {:max_quantity => 3}} + spree_post :populate, variants: { p.master.id => 1 }, variant_attributes: { p.master.id => {max_quantity: 3 } } end.to change(Spree::LineItem, :count).by(1) end it "returns HTTP success when successful" do - CartService.stub(:new).and_return(cart_service = double()) - cart_service.stub(:populate) { true } - cart_service.stub(:variants_h) { {} } + allow(CartService).to receive(:new).and_return(cart_service = double()) + allow(cart_service).to receive(:populate) { true } + allow(cart_service).to receive(:variants_h) { {} } xhr :post, :populate, use_route: :spree, format: :json - response.status.should == 200 + expect(response.status).to eq(200) end it "returns failure when unsuccessful" do - CartService.stub(:new).and_return(cart_service = double()) - cart_service.stub(:populate).and_return false + allow(CartService).to receive(:new).and_return(cart_service = double()) + allow(cart_service).to receive(:populate).and_return false xhr :post, :populate, use_route: :spree, format: :json - response.status.should == 412 + expect(response.status).to eq(412) end it "tells cart_service to overwrite" do - CartService.stub(:new).and_return(cart_service = double()) - cart_service.should_receive(:populate).with({}, true) + allow(CartService).to receive(:new).and_return(cart_service = double()) + expect(cart_service).to receive(:populate).with({}, true) xhr :post, :populate, use_route: :spree, format: :json end end diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 86f232c48f..b9012ff890 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -7,40 +7,40 @@ describe Spree::OrdersController, type: :controller do it "redirects home when no distributor is selected" do spree_get :edit - response.should redirect_to root_path + expect(response).to redirect_to root_path end it "redirects to shop when order is empty" do - controller.stub(:current_distributor).and_return(distributor) - controller.stub(:current_order_cycle).and_return(order_cycle) - controller.stub(:current_order).and_return order - order.stub_chain(:line_items, :empty?).and_return true - order.stub(:insufficient_stock_lines).and_return [] + allow(controller).to receive(:current_distributor).and_return(distributor) + allow(controller).to receive(:current_order_cycle).and_return(order_cycle) + allow(controller).to receive(:current_order).and_return order + allow(order).to receive_message_chain(:line_items, :empty?).and_return true + allow(order).to receive(:insufficient_stock_lines).and_return [] session[:access_token] = order.token spree_get :edit - response.should redirect_to shop_path + expect(response).to redirect_to shop_path end it "redirects to the shop when no order cycle is selected" do - controller.stub(:current_distributor).and_return(distributor) + allow(controller).to receive(:current_distributor).and_return(distributor) spree_get :edit - response.should redirect_to shop_path + expect(response).to redirect_to shop_path end it "redirects home with message if hub is not ready for checkout" do - VariantOverride.stub(:indexed).and_return({}) + allow(VariantOverride).to receive(:indexed).and_return({}) order = subject.current_order(true) - distributor.stub(:ready_for_checkout?) { false } - order.stub(distributor: distributor, order_cycle: order_cycle) + allow(distributor).to receive(:ready_for_checkout?) { false } + allow(order).to receive_messages(distributor: distributor, order_cycle: order_cycle) - order.should_receive(:empty!) - order.should_receive(:set_distribution!).with(nil, nil) + expect(order).to receive(:empty!) + expect(order).to receive(:set_distribution!).with(nil, nil) spree_get :edit - response.should redirect_to root_url - flash[:info].should == "The hub you have selected is temporarily closed for orders. Please try again later." + expect(response).to redirect_to root_url + expect(flash[:info]).to eq("The hub you have selected is temporarily closed for orders. Please try again later.") end describe "when an item has insufficient stock" do @@ -59,7 +59,7 @@ describe Spree::OrdersController, type: :controller do it "displays a flash message when we view the cart" do spree_get :edit expect(response.status).to eq 200 - flash[:error].should == "An item in your cart has become unavailable." + expect(flash[:error]).to eq("An item in your cart has become unavailable.") end end @@ -72,8 +72,8 @@ describe Spree::OrdersController, type: :controller do "0" => {quantity: "0", id: "9999"}, "1" => {quantity: "99", id: li.id} }} - response.status.should == 302 - li.reload.quantity.should == 99 + expect(response.status).to eq(302) + expect(li.reload.quantity).to eq(99) end end @@ -86,9 +86,9 @@ describe Spree::OrdersController, type: :controller do "1" => {quantity: "99", id: li.id} } - controller.remove_missing_line_items(attrs).should == { + expect(controller.remove_missing_line_items(attrs)).to eq({ "1" => {quantity: "99", id: li.id} - } + }) end end @@ -159,7 +159,7 @@ describe Spree::OrdersController, type: :controller do it "updates the fees" do expect(order.reload.adjustment_total).to eq enterprise_fee.calculator.preferred_amount - controller.stub spree_current_user: user + allow(controller).to receive_messages spree_current_user: user spree_post :update, params expect(order.reload.adjustment_total).to eq enterprise_fee.calculator.preferred_amount * 2 diff --git a/spec/services/cart_service_spec.rb b/spec/services/cart_service_spec.rb index caa8afe2a5..3f0f4e0597 100644 --- a/spec/services/cart_service_spec.rb +++ b/spec/services/cart_service_spec.rb @@ -19,10 +19,10 @@ describe CartService do it "adds a variant" do cart_service.populate({variants: {v.id.to_s => {quantity: '1', max_quantity: '2'}}}, true) li = order.find_line_item_by_variant(v) - li.should be - li.quantity.should == 1 - li.max_quantity.should == 2 - li.final_weight_volume.should == 1.0 + expect(li).to be + expect(li.quantity).to eq(1) + expect(li.max_quantity).to eq(2) + expect(li.final_weight_volume).to eq(1.0) end it "updates a variant's quantity, max quantity and final_weight_volume" do @@ -30,10 +30,10 @@ describe CartService do cart_service.populate({variants: {v.id.to_s => {quantity: '2', max_quantity: '3'}}}, true) li = order.find_line_item_by_variant(v) - li.should be - li.quantity.should == 2 - li.max_quantity.should == 3 - li.final_weight_volume.should == 2.0 + expect(li).to be + expect(li.quantity).to eq(2) + expect(li.max_quantity).to eq(3) + expect(li.final_weight_volume).to eq(2.0) end it "removes a variant" do @@ -42,38 +42,38 @@ describe CartService do cart_service.populate({variants: {}}, true) order.line_items(:reload) li = order.find_line_item_by_variant(v) - li.should_not be + expect(li).not_to be end end end describe "populate" do before do - cart_service.should_receive(:distributor_and_order_cycle). + expect(cart_service).to receive(:distributor_and_order_cycle). and_return([distributor, order_cycle]) end it "checks that distribution can supply all products in the cart" do - cart_service.should_receive(:distribution_can_supply_products_in_cart). + expect(cart_service).to receive(:distribution_can_supply_products_in_cart). with(distributor, order_cycle).and_return(false) - cart_service.populate(params).should be false - cart_service.errors.to_a.should == ["That distributor or order cycle can't supply all the products in your cart. Please choose another."] + expect(cart_service.populate(params)).to be false + expect(cart_service.errors.to_a).to eq(["That distributor or order cycle can't supply all the products in your cart. Please choose another."]) end it "locks the order" do - cart_service.stub(:distribution_can_supply_products_in_cart).and_return(true) - order.should_receive(:with_lock) + allow(cart_service).to receive(:distribution_can_supply_products_in_cart).and_return(true) + expect(order).to receive(:with_lock) cart_service.populate(params, true) end it "attempts cart add with max_quantity" do - cart_service.stub(:distribution_can_supply_products_in_cart).and_return true + allow(cart_service).to receive(:distribution_can_supply_products_in_cart).and_return true params = {variants: {"1" => {quantity: 1, max_quantity: 2}}} - order.stub(:with_lock).and_yield - cart_service.stub(:varies_from_cart) { true } - cart_service.stub(:variants_removed) { [] } - cart_service.should_receive(:attempt_cart_add).with("1", 1, 2).and_return true + allow(order).to receive(:with_lock).and_yield + allow(cart_service).to receive(:varies_from_cart) { true } + allow(cart_service).to receive(:variants_removed) { [] } + expect(cart_service).to receive(:attempt_cart_add).with("1", 1, 2).and_return true cart_service.populate(params, true) end end @@ -82,68 +82,68 @@ describe CartService do let(:variant) { double(:variant, id: 123) } it "returns true when item is not in cart and a quantity is specified" do - cart_service.should_receive(:line_item_for_variant_id).with(variant.id).and_return(nil) - cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '2'}).should be true + expect(cart_service).to receive(:line_item_for_variant_id).with(variant.id).and_return(nil) + expect(cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '2'})).to be true end it "returns true when item is not in cart and a max_quantity is specified" do - cart_service.should_receive(:line_item_for_variant_id).with(variant.id).and_return(nil) - cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '0', max_quantity: '2'}).should be true + expect(cart_service).to receive(:line_item_for_variant_id).with(variant.id).and_return(nil) + expect(cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '0', max_quantity: '2'})).to be true end it "returns false when item is not in cart and no quantity or max_quantity are specified" do - cart_service.should_receive(:line_item_for_variant_id).with(variant.id).and_return(nil) - cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '0'}).should be false + expect(cart_service).to receive(:line_item_for_variant_id).with(variant.id).and_return(nil) + expect(cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '0'})).to be false end it "returns true when quantity varies" do li = double(:line_item, quantity: 1, max_quantity: nil) - cart_service.stub(:line_item_for_variant_id) { li } + allow(cart_service).to receive(:line_item_for_variant_id) { li } - cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '2'}).should be true + expect(cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '2'})).to be true end it "returns true when max_quantity varies" do li = double(:line_item, quantity: 1, max_quantity: nil) - cart_service.stub(:line_item_for_variant_id) { li } + allow(cart_service).to receive(:line_item_for_variant_id) { li } - cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '1', max_quantity: '3'}).should be true + expect(cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '1', max_quantity: '3'})).to be true end it "returns false when max_quantity varies only in nil vs 0" do li = double(:line_item, quantity: 1, max_quantity: nil) - cart_service.stub(:line_item_for_variant_id) { li } + allow(cart_service).to receive(:line_item_for_variant_id) { li } - cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '1'}).should be false + expect(cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '1'})).to be false end it "returns false when both are specified and neither varies" do li = double(:line_item, quantity: 1, max_quantity: 2) - cart_service.stub(:line_item_for_variant_id) { li } + allow(cart_service).to receive(:line_item_for_variant_id) { li } - cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '1', max_quantity: '2'}).should be false + expect(cart_service.send(:varies_from_cart, {variant_id: variant.id, quantity: '1', max_quantity: '2'})).to be false end end describe "variants_removed" do it "returns the variant ids when one is in the cart but not in those given" do - cart_service.stub(:variant_ids_in_cart) { [123] } - cart_service.send(:variants_removed, []).should == [123] + allow(cart_service).to receive(:variant_ids_in_cart) { [123] } + expect(cart_service.send(:variants_removed, [])).to eq([123]) end it "returns nothing when all items in the cart are provided" do - cart_service.stub(:variant_ids_in_cart) { [123] } - cart_service.send(:variants_removed, [{variant_id: '123'}]).should == [] + allow(cart_service).to receive(:variant_ids_in_cart) { [123] } + expect(cart_service.send(:variants_removed, [{variant_id: '123'}])).to eq([]) end it "returns nothing when items are added to cart" do - cart_service.stub(:variant_ids_in_cart) { [123] } - cart_service.send(:variants_removed, [{variant_id: '123'}, {variant_id: '456'}]).should == [] + allow(cart_service).to receive(:variant_ids_in_cart) { [123] } + expect(cart_service.send(:variants_removed, [{variant_id: '123'}, {variant_id: '456'}])).to eq([]) end it "does not return duplicates" do - cart_service.stub(:variant_ids_in_cart) { [123, 123] } - cart_service.send(:variants_removed, []).should == [123] + allow(cart_service).to receive(:variant_ids_in_cart) { [123, 123] } + expect(cart_service.send(:variants_removed, [])).to eq([123]) end end @@ -152,40 +152,40 @@ describe CartService do let(:quantity) { 123 } before do - Spree::Variant.stub(:find).and_return(variant) - VariantOverride.stub(:for).and_return(nil) + allow(Spree::Variant).to receive(:find).and_return(variant) + allow(VariantOverride).to receive(:for).and_return(nil) end it "performs additional validations" do - cart_service.should_receive(:check_order_cycle_provided_for).with(variant).and_return(true) - cart_service.should_receive(:check_variant_available_under_distribution).with(variant). + expect(cart_service).to receive(:check_order_cycle_provided_for).with(variant).and_return(true) + expect(cart_service).to receive(:check_variant_available_under_distribution).with(variant). and_return(true) - order.should_receive(:add_variant).with(variant, quantity, nil, currency) + expect(order).to receive(:add_variant).with(variant, quantity, nil, currency) cart_service.attempt_cart_add(333, quantity.to_s) end it "filters quantities through #quantities_to_add" do - cart_service.should_receive(:quantities_to_add).with(variant, 123, 123). + expect(cart_service).to receive(:quantities_to_add).with(variant, 123, 123). and_return([5, 5]) - cart_service.stub(:check_order_cycle_provided_for) { true } - cart_service.stub(:check_variant_available_under_distribution) { true } + allow(cart_service).to receive(:check_order_cycle_provided_for) { true } + allow(cart_service).to receive(:check_variant_available_under_distribution) { true } - order.should_receive(:add_variant).with(variant, 5, 5, currency) + expect(order).to receive(:add_variant).with(variant, 5, 5, currency) cart_service.attempt_cart_add(333, quantity.to_s, quantity.to_s) end it "removes variants which have become out of stock" do - cart_service.should_receive(:quantities_to_add).with(variant, 123, 123). + expect(cart_service).to receive(:quantities_to_add).with(variant, 123, 123). and_return([0, 0]) - cart_service.stub(:check_order_cycle_provided_for) { true } - cart_service.stub(:check_variant_available_under_distribution) { true } + allow(cart_service).to receive(:check_order_cycle_provided_for) { true } + allow(cart_service).to receive(:check_variant_available_under_distribution) { true } - order.should_receive(:remove_variant).with(variant) - order.should_receive(:add_variant).never + expect(order).to receive(:remove_variant).with(variant) + expect(order).to receive(:add_variant).never cart_service.attempt_cart_add(333, quantity.to_s, quantity.to_s) end @@ -197,21 +197,21 @@ describe CartService do context "when backorders are not allowed" do context "when max_quantity is not provided" do it "returns full amount when available" do - cart_service.quantities_to_add(v, 5, nil).should == [5, nil] + expect(cart_service.quantities_to_add(v, 5, nil)).to eq([5, nil]) end it "returns a limited amount when not entirely available" do - cart_service.quantities_to_add(v, 15, nil).should == [10, nil] + expect(cart_service.quantities_to_add(v, 15, nil)).to eq([10, nil]) end end context "when max_quantity is provided" do it "returns full amount when available" do - cart_service.quantities_to_add(v, 5, 6).should == [5, 6] + expect(cart_service.quantities_to_add(v, 5, 6)).to eq([5, 6]) end it "also returns the full amount when not entirely available" do - cart_service.quantities_to_add(v, 15, 16).should == [10, 16] + expect(cart_service.quantities_to_add(v, 15, 16)).to eq([10, 16]) end end end @@ -222,11 +222,11 @@ describe CartService do end it "does not limit quantity" do - cart_service.quantities_to_add(v, 15, nil).should == [15, nil] + expect(cart_service.quantities_to_add(v, 15, nil)).to eq([15, nil]) end it "does not limit max_quantity" do - cart_service.quantities_to_add(v, 15, 16).should == [15, 16] + expect(cart_service.quantities_to_add(v, 15, 16)).to eq([15, 16]) end end end @@ -235,9 +235,9 @@ describe CartService do describe "determining if distributor can supply products in cart" do it "delegates to DistributionChangeValidator" do dcv = double(:dcv) - dcv.should_receive(:can_change_to_distribution?).with(distributor, order_cycle).and_return(true) - DistributionChangeValidator.should_receive(:new).with(order).and_return(dcv) - cart_service.send(:distribution_can_supply_products_in_cart, distributor, order_cycle).should be true + expect(dcv).to receive(:can_change_to_distribution?).with(distributor, order_cycle).and_return(true) + expect(DistributionChangeValidator).to receive(:new).with(order).and_return(dcv) + expect(cart_service.send(:distribution_can_supply_products_in_cart, distributor, order_cycle)).to be true end end @@ -245,18 +245,18 @@ describe CartService do let(:variant) { double(:variant) } it "returns false and errors when order cycle is not provided and is required" do - cart_service.stub(:order_cycle_required_for).and_return true - cart_service.send(:check_order_cycle_provided_for, variant).should be false - cart_service.errors.to_a.should == ["Please choose an order cycle for this order."] + allow(cart_service).to receive(:order_cycle_required_for).and_return true + expect(cart_service.send(:check_order_cycle_provided_for, variant)).to be false + expect(cart_service.errors.to_a).to eq(["Please choose an order cycle for this order."]) end it "returns true when order cycle is provided" do - cart_service.stub(:order_cycle_required_for).and_return true + allow(cart_service).to receive(:order_cycle_required_for).and_return true cart_service.instance_variable_set :@order_cycle, double(:order_cycle) - cart_service.send(:check_order_cycle_provided_for, variant).should be true + expect(cart_service.send(:check_order_cycle_provided_for, variant)).to be true end it "returns true when order cycle is not required" do - cart_service.stub(:order_cycle_required_for).and_return false - cart_service.send(:check_order_cycle_provided_for, variant).should be true + allow(cart_service).to receive(:order_cycle_required_for).and_return false + expect(cart_service.send(:check_order_cycle_provided_for, variant)).to be true end end @@ -266,20 +266,20 @@ describe CartService do it "delegates to DistributionChangeValidator, returning true when available" do dcv = double(:dcv) - dcv.should_receive(:variants_available_for_distribution).with(123, 234).and_return([variant]) - DistributionChangeValidator.should_receive(:new).with(order).and_return(dcv) + expect(dcv).to receive(:variants_available_for_distribution).with(123, 234).and_return([variant]) + expect(DistributionChangeValidator).to receive(:new).with(order).and_return(dcv) cart_service.instance_eval { @distributor = 123; @order_cycle = 234 } - cart_service.send(:check_variant_available_under_distribution, variant).should be true - cart_service.errors.should be_empty + expect(cart_service.send(:check_variant_available_under_distribution, variant)).to be true + expect(cart_service.errors).to be_empty end it "delegates to DistributionChangeValidator, returning false and erroring otherwise" do dcv = double(:dcv) - dcv.should_receive(:variants_available_for_distribution).with(123, 234).and_return([]) - DistributionChangeValidator.should_receive(:new).with(order).and_return(dcv) + expect(dcv).to receive(:variants_available_for_distribution).with(123, 234).and_return([]) + expect(DistributionChangeValidator).to receive(:new).with(order).and_return(dcv) cart_service.instance_eval { @distributor = 123; @order_cycle = 234 } - cart_service.send(:check_variant_available_under_distribution, variant).should be false - cart_service.errors.to_a.should == ["That product is not available from the chosen distributor or order cycle."] + expect(cart_service.send(:check_variant_available_under_distribution, variant)).to be false + expect(cart_service.errors.to_a).to eq(["That product is not available from the chosen distributor or order cycle."]) end end end @@ -290,21 +290,21 @@ describe CartService do it "requires an order cycle when the product has no product distributions" do product = double(:product, product_distributions: []) variant = double(:variant, product: product) - cart_service.send(:order_cycle_required_for, variant).should be true + expect(cart_service.send(:order_cycle_required_for, variant)).to be true end it "does not require an order cycle when the product has product distributions" do product = double(:product, product_distributions: [1]) variant = double(:variant, product: product) - cart_service.send(:order_cycle_required_for, variant).should be false + expect(cart_service.send(:order_cycle_required_for, variant)).to be false end end it "provides the distributor and order cycle for the order" do - order.should_receive(:distributor).and_return(distributor) - order.should_receive(:order_cycle).and_return(order_cycle) - cart_service.send(:distributor_and_order_cycle).should == [distributor, - order_cycle] + expect(order).to receive(:distributor).and_return(distributor) + expect(order).to receive(:order_cycle).and_return(order_cycle) + expect(cart_service.send(:distributor_and_order_cycle)).to eq([distributor, + order_cycle]) end end end