Skip to content

Commit

Permalink
Convert specs to RSpec 2.99.2 syntax with Transpec
Browse files Browse the repository at this point in the history
This conversion is done by Transpec 3.1.0 with the following command:
    transpec

* 46 conversions
    from: obj.should
      to: expect(obj).to

* 23 conversions
    from: == expected
      to: eq(expected)

* 9 conversions
    from: obj.should_receive(:message)
      to: expect(obj).to receive(:message)

* 4 conversions
    from: obj.stub(:message)
      to: allow(obj).to receive(:message)

* 1 conversion
    from: obj.should_not_receive(:message)
      to: expect(obj).not_to receive(:message)

For more details: https://github.com/yujinakayama/transpec#supported-conversions
  • Loading branch information
jspizziri committed Apr 2, 2015
1 parent 5849adc commit 699225a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
14 changes: 7 additions & 7 deletions spec/controllers/admin/product_packages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
48 changes: 24 additions & 24 deletions spec/models/active_shipping_calculator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -59,38 +59,38 @@ 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

context "when rates are not available" do
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
Expand All @@ -100,17 +100,17 @@ 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

describe "compute" do
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
Expand All @@ -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
Expand Down
40 changes: 20 additions & 20 deletions spec/models/weight_limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -107,58 +107,58 @@ 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

describe "validation of line item weight" do
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

describe "validation of default weight of zero" do
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
Expand Down

0 comments on commit 699225a

Please sign in to comment.