diff --git a/spec/controllers/admin/active_shipping_settings_controller_spec.rb b/spec/controllers/admin/active_shipping_settings_controller_spec.rb index dc983bbd55..1333c7a993 100644 --- a/spec/controllers/admin/active_shipping_settings_controller_spec.rb +++ b/spec/controllers/admin/active_shipping_settings_controller_spec.rb @@ -6,8 +6,8 @@ context '#edit' do it 'should assign a Spree::ActiveShippingConfiguration and render the view' do spree_get :edit - assigns(:config).should be_an_instance_of(Spree::ActiveShippingConfiguration) - response.should render_template('edit') + expect(assigns(:config)).to be_an_instance_of(Spree::ActiveShippingConfiguration) + expect(response).to render_template('edit') end end @@ -19,28 +19,28 @@ it "should allow us to set the value of #{name}" do new_val = SecureRandom.random_number(100) spree_post :update, name => new_val - Spree::ActiveShippingConfiguration.new.send("preferred_#{name}").should eq(new_val) - response.should redirect_to(spree.edit_admin_active_shipping_settings_path) + expect(Spree::ActiveShippingConfiguration.new.send("preferred_#{name}")).to eq(new_val) + expect(response).to redirect_to(spree.edit_admin_active_shipping_settings_path) end when :string it "should allow us to set the value of #{name}" do new_val = SecureRandom.hex(5) spree_post :update, name => new_val - Spree::ActiveShippingConfiguration.new.send("preferred_#{name}").should eq(new_val) - response.should redirect_to(spree.edit_admin_active_shipping_settings_path) + expect(Spree::ActiveShippingConfiguration.new.send("preferred_#{name}")).to eq(new_val) + expect(response).to redirect_to(spree.edit_admin_active_shipping_settings_path) end when :boolean it "should allow us to switch the value of #{name}" do spree_post :update, name => !orig_val - Spree::ActiveShippingConfiguration.new.send("preferred_#{name}").should eq(!orig_val) - response.should redirect_to(spree.edit_admin_active_shipping_settings_path) + expect(Spree::ActiveShippingConfiguration.new.send("preferred_#{name}")).to eq(!orig_val) + expect(response).to redirect_to(spree.edit_admin_active_shipping_settings_path) end end end it "doesn't product an error when passed an invalid parameter name" do spree_post :update, 'not_real_parameter_name' => 'not_real' - response.should redirect_to(spree.edit_admin_active_shipping_settings_path) + expect(response).to redirect_to(spree.edit_admin_active_shipping_settings_path) end end end \ No newline at end of file diff --git a/spec/controllers/admin/product_packages_controller_spec.rb b/spec/controllers/admin/product_packages_controller_spec.rb index c6d4807a72..e1ecc191fd 100644 --- a/spec/controllers/admin/product_packages_controller_spec.rb +++ b/spec/controllers/admin/product_packages_controller_spec.rb @@ -8,9 +8,9 @@ it 'should find ProductPackages for the product and render the view' do spree_get :index, product_id: product.slug - assigns(:product).should eq(product) - response.should be_ok - response.should render_template('index') + expect(assigns(:product)).to eq(product) + expect(response).to be_ok + expect(response).to render_template('index') end end @@ -27,10 +27,10 @@ product_package: { length: new_length, width: new_width, height: new_height, weight: new_weight } product_package.reload - product_package.length.should eq(new_length) - product_package.width.should eq(new_width) - product_package.height.should eq(new_height) - product_package.weight.should eq(new_weight) + expect(product_package.length).to eq(new_length) + expect(product_package.width).to eq(new_width) + expect(product_package.height).to eq(new_height) + expect(product_package.weight).to eq(new_weight) end end end \ No newline at end of file diff --git a/spec/models/active_shipping_calculator_spec.rb b/spec/models/active_shipping_calculator_spec.rb index 65976db202..e54bfbff94 100644 --- a/spec/models/active_shipping_calculator_spec.rb +++ b/spec/models/active_shipping_calculator_spec.rb @@ -38,10 +38,10 @@ module ActiveShipping Spree::StockLocation.destroy_all stock_location order.create_proposed_shipments - order.shipments.count.should == 1 + expect(order.shipments.count).to eq(1) Spree::ActiveShipping::Config.set(:units => "imperial") Spree::ActiveShipping::Config.set(:unit_multiplier => 1) - calculator.stub(:carrier).and_return(carrier) + allow(calculator).to receive(:carrier).and_return(carrier) Rails.cache.clear end @@ -59,16 +59,16 @@ module ActiveShipping end before do - carrier.should_receive(:find_rates).and_return(response) + expect(carrier).to receive(:find_rates).and_return(response) end it "should return true" do - calculator.available?(package).should be(true) + expect(calculator.available?(package)).to be(true) end it "should use zero as a valid weight for service" do - calculator.stub(:max_weight_for_country).and_return(0) - calculator.available?(package).should be(true) + allow(calculator).to receive(:max_weight_for_country).and_return(0) + expect(calculator.available?(package)).to be(true) end end @@ -76,21 +76,21 @@ module ActiveShipping let(:rates) { [] } before do - carrier.should_receive(:find_rates).and_return(response) + expect(carrier).to receive(:find_rates).and_return(response) end it "should return false" do - calculator.available?(package).should be(false) + expect(calculator.available?(package)).to be(false) end end context "when there is an error retrieving the rates" do before do - carrier.should_receive(:find_rates).and_raise(ActiveMerchant::ActiveMerchantError) + expect(carrier).to receive(:find_rates).and_raise(ActiveMerchant::ActiveMerchantError) end it "should return false" do - calculator.available?(package).should be(false) + expect(calculator.available?(package)).to be(false) end end end @@ -100,9 +100,9 @@ module ActiveShipping it "should not return rates if the weight requirements for the destination country are not met" do # if max_weight_for_country is nil -> the carrier does not ship to that country # if max_weight_for_country is 0 -> the carrier does not have weight restrictions to that country - calculator.stub(:max_weight_for_country).and_return(nil) - calculator.should_receive(:is_package_shippable?).and_raise Spree::ShippingError - calculator.available?(package).should be(false) + allow(calculator).to receive(:max_weight_for_country).and_return(nil) + expect(calculator).to receive(:is_package_shippable?).and_raise Spree::ShippingError + expect(calculator.available?(package)).to be(false) end end @@ -110,7 +110,7 @@ module ActiveShipping it "should use the carrier supplied in the initializer" do stub_request(:get, /http:\/\/production.shippingapis.com\/ShippingAPI.dll.*/). to_return(:body => fixture(:normal_rates_request)) - calculator.compute(package).should == 14.1 + expect(calculator.compute(package)).to eq(14.1) end xit "should ignore variants that have a nil weight" do @@ -122,45 +122,45 @@ module ActiveShipping xit "should create a package with the correct total weight in ounces" do # (10 * 2 + 5.25 * 1) * 16 = 404 - Package.should_receive(:new).with(404, [], :units => :imperial) + expect(Package).to receive(:new).with(404, [], :units => :imperial) calculator.compute(package) end xit "should check the cache first before finding rates" do Rails.cache.fetch(calculator.send(:cache_key, order)) { Hash.new } - carrier.should_not_receive(:find_rates) + expect(carrier).not_to receive(:find_rates) calculator.compute(package) end context "with valid response" do before do - carrier.should_receive(:find_rates).and_return(response) + expect(carrier).to receive(:find_rates).and_return(response) end xit "should return rate based on calculator's service_name" do - calculator.class.should_receive(:description).and_return("Super Fast") + expect(calculator.class).to receive(:description).and_return("Super Fast") rate = calculator.compute(package) - rate.should == 9.99 + expect(rate).to eq(9.99) end xit "should include handling_fee when configured" do - calculator.class.should_receive(:description).and_return("Super Fast") + expect(calculator.class).to receive(:description).and_return("Super Fast") Spree::ActiveShipping::Config.set(:handling_fee => 100) rate = calculator.compute(package) - rate.should == 10.99 + expect(rate).to eq(10.99) end xit "should return nil if service_name is not found in rate_hash" do - calculator.class.should_receive(:description).and_return("Extra-Super Fast") + expect(calculator.class).to receive(:description).and_return("Extra-Super Fast") rate = calculator.compute(package) - rate.should be_nil + expect(rate).to be_nil end end end describe "service_name" do it "should return description when not defined" do - calculator.class.service_name.should == calculator.description + expect(calculator.class.service_name).to eq(calculator.description) end end end diff --git a/spec/models/weight_limits_spec.rb b/spec/models/weight_limits_spec.rb index 64be3a13a8..bec4a28773 100644 --- a/spec/models/weight_limits_spec.rb +++ b/spec/models/weight_limits_spec.rb @@ -84,19 +84,19 @@ def build_inventory_unit(variant, order) active_shipping_weights = [20.0, 21.0, 29.0, 60.0, 60.0, 60.0].map do |x| (x * Spree::ActiveShipping::Config[:unit_multiplier]).to_d end - weights.should match_array active_shipping_weights + expect(weights).to match_array active_shipping_weights end it "should create array of packages" do packages = international_calculator.send :packages, package - packages.size.should == 5 - packages.map{|package| package.weight.amount}.should == [41.0, 29.0, 60.0, 60.0, 60.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]} - packages.map{|package| package.weight.unit}.uniq.should == [:ounces] + expect(packages.size).to eq(5) + expect(packages.map{|package| package.weight.amount}).to eq([41.0, 29.0, 60.0, 60.0, 60.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]}) + expect(packages.map{|package| package.weight.unit}.uniq).to eq([:ounces]) end context "raise exception if max weight exceeded" do it "should get Spree::ShippingError" do - too_heavy_package.stub(:weight) do + allow(too_heavy_package).to receive(:weight) do too_heavy_package.contents.sum{ |item| item.variant.weight * item.quantity } end expect { international_calculator.compute(too_heavy_package) }.to raise_error(Spree::ShippingError) @@ -107,33 +107,33 @@ def build_inventory_unit(variant, order) context "for domestic calculators" do it "should not convert order line items to weights array for US" do weights = domestic_calculator.send :convert_package_to_weights_array, us_package - weights.should == [5.25, 5.25, 5.25, 5.25, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 29.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]} + expect(weights).to eq([5.25, 5.25, 5.25, 5.25, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 29.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]}) end it "should create array with one package for US" do packages = domestic_calculator.send :packages, us_package - packages.size.should == 4 - packages.map{|package| package.weight.amount}.should == [61.0, 60.0, 60.0, 69.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]} - packages.map{|package| package.weight.unit}.uniq.should == [:ounces] + expect(packages.size).to eq(4) + expect(packages.map{|package| package.weight.amount}).to eq([61.0, 60.0, 60.0, 69.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]}) + expect(packages.map{|package| package.weight.unit}.uniq).to eq([:ounces]) end end end describe "weight limits" do it "should be set for USPS calculators" do - international_calculator.send(:max_weight_for_country, country).should == 66.0 * Spree::ActiveShipping::Config[:unit_multiplier] # Canada - domestic_calculator.send(:max_weight_for_country, country).should == 70.0 * Spree::ActiveShipping::Config[:unit_multiplier] + expect(international_calculator.send(:max_weight_for_country, country)).to eq(66.0 * Spree::ActiveShipping::Config[:unit_multiplier]) # Canada + expect(domestic_calculator.send(:max_weight_for_country, country)).to eq(70.0 * Spree::ActiveShipping::Config[:unit_multiplier]) end it "should respect the max weight per package" do Spree::ActiveShipping::Config.set(:max_weight_per_package => 30) weights = international_calculator.send :convert_package_to_weights_array, package - weights.should == [5.25, 5.25, 5.25, 5.25, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 29.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]} + expect(weights).to eq([5.25, 5.25, 5.25, 5.25, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 29.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]}) packages = international_calculator.send :packages, package - packages.size.should == 12 - packages.map{|package| package.weight.amount}.should == [21.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 29.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]} - packages.map{|package| package.weight.unit}.uniq.should == [:ounces] + expect(packages.size).to eq(12) + expect(packages.map{|package| package.weight.amount}).to eq([21.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 20.0, 29.0].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]}) + expect(packages.map{|package| package.weight.unit}.uniq).to eq([:ounces]) end end @@ -141,7 +141,7 @@ def build_inventory_unit(variant, order) it "should avoid zero weight or negative weight" do weights = domestic_calculator.send :convert_package_to_weights_array, package_with_invalid_weights default_weight = Spree::ActiveShipping::Config[:default_weight] * Spree::ActiveShipping::Config[:unit_multiplier] - weights.should == [default_weight, default_weight] + expect(weights).to eq([default_weight, default_weight]) end end @@ -149,16 +149,16 @@ def build_inventory_unit(variant, order) it "should accept zero default weight" do Spree::ActiveShipping::Config.set(:default_weight => 0) weights = domestic_calculator.send :convert_package_to_weights_array, package_with_invalid_weights - weights.should == [0, 0] + expect(weights).to eq([0, 0]) end end describe "adds item packages" do it "should add item packages to weight calculation" do packages = domestic_calculator.send :packages, package_with_packages - packages.size.should == 6 - packages.map{|package| package.weight.amount}.should == [50, 29, 36, 43, 36, 43].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]} - packages.map{|package| package.weight.unit}.uniq.should == [:ounces] + expect(packages.size).to eq(6) + expect(packages.map{|package| package.weight.amount}).to eq([50, 29, 36, 43, 36, 43].map{|x| x * Spree::ActiveShipping::Config[:unit_multiplier]}) + expect(packages.map{|package| package.weight.unit}.uniq).to eq([:ounces]) end end end