<commit_before>require 'spec_helper'

module Spree::Shipping
  describe RateBuilder do
    let(:builder){RateBuilder.new(package, shipping_method, ship_time)}
    let(:package){build(:stock_package_fulfilled)}
    let(:shipping_method){build(:shipping_method)}
    let(:calculator) do
      calculator = double("Calculator")
      allow(calculator).to receive(:estimate_delivery_window).and_return(delivery_window)
      allow(calculator).to receive(:compute_package)
      calculator
    end
    let(:delivery_window){DeliveryWindow.new(ship_time + 2.days, ship_time + 3.days)}
    let(:ship_time){Time.now.beginning_of_day + 18.hours}

    before(:each) do
      allow(shipping_method).to receive(:calculator).and_return(calculator)
    end
    
    context '#rate' do
      let(:rate){builder.rate}
      it 'returns an instance of Spree::ShippingRate' do
        expect(rate).to be_instance_of(Spree::ShippingRate)
      end
      it 'requests the delivery window from the shipping method\'s calculator' do
        builder.rate
        expect(calculator).to have_received(:estimate_delivery_window).with(package, ship_time)
      end
      it 'requests the cost from the shipping method\'s calculator' do
        builder.rate
        expect(calculator).to have_received(:compute_package).with(package)
      end
      
      context 'with calculator that doesn\'t estimate windows' do
        let(:calculator) do
          calculator = double("Calculator")
          allow(calculator).to receive(:compute_package)
          calculator
        end
        it 'has a nil delivery window' do
          expect(rate.delivery_window.start).to be_nil
          expect(rate.delivery_window.end).to be_nil
        end
      end
    end
  end
end<commit_msg>Test fixes<commit_after>require 'spec_helper'

module Spree::Shipping
  describe RateBuilder do
    let(:builder){RateBuilder.new(package, shipping_method, ship_time)}
    let(:package){build(:stock_package_fulfilled)}
    let(:shipping_method){build(:shipping_method)}
    let(:calculator) do
      calculator = double("Calculator")
      allow(calculator).to receive(:estimate_delivery_window).and_return(delivery_window)
      allow(calculator).to receive(:compute_package)
      calculator
    end
    let(:delivery_window){DeliveryWindow.new(ship_time + 2.days, ship_time + 3.days)}
    let(:ship_time){Time.now.beginning_of_day + 18.hours}

    before(:each) do
      allow(shipping_method).to receive(:calculator).and_return(calculator)
    end
    
    context '#rate' do
      let!(:rate){builder.rate}
      it 'returns an instance of Spree::ShippingRate' do
        expect(rate).to be_instance_of(Spree::ShippingRate)
      end
      it 'has a delivery window' do
        expect(rate.delivery_window.start).to eq(delivery_window.start)
        expect(rate.delivery_window.end).to eq(delivery_window.end)
      end
      it 'requests the delivery window from the shipping method\'s calculator' do
        expect(calculator).to have_received(:estimate_delivery_window).with(package, ship_time)
      end
      it 'requests the cost from the shipping method\'s calculator' do
        expect(calculator).to have_received(:compute_package).with(package)
      end
      
      context 'with calculator that doesn\'t estimate windows' do
        let(:calculator) do
          calculator = double("Calculator")
          allow(calculator).to receive(:compute_package)
          calculator
        end
        it 'has a nil delivery window' do
          expect(rate.delivery_window.start).to be_nil
          expect(rate.delivery_window.end).to be_nil
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09736697750959956, 'fraction_numerical': 0.0021941854086670325, 'mean_word_length': 3.2855464159811985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3513313', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1053, 'n_words': 227}