Sha256: 512ee4d5e2343bb9d0b22020b264e1d6bf30b89a0bfa3639a89b3b96a58bacf6

Contents?: true

Size: 1.08 KB

Versions: 48

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Spree::Calculator, type: :model do
  class SimpleCalculator < Spree::Calculator
    def compute_simple_computable(_line_item)
      'computed'
    end
  end

  class SimpleComputable
  end

  describe "#calculators" do
    subject { Spree::Calculator.calculators }

    it 'returns the (deprecated) calculator step' do
      Spree::Deprecation.silence do
        expect(subject).to be_a Spree::Core::Environment::Calculators
      end
    end
  end

  context "with computable" do
    let(:calculator) { SimpleCalculator.new }
    let(:computable) { SimpleComputable.new }

    subject { SimpleCalculator.new.compute computable }

    it 'calls compute method of class type' do
      expect(subject).to eq  'computed'
    end

    context 'computable does not implement right function name' do
      let(:computable) { Spree::LineItem.new }

      it 'raises an error' do
        expect { subject }.to raise_error NotImplementedError, /Please implement \'compute_line_item\(line_item\)\' in your calculator/
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/calculator_spec.rb
solidus_core-2.10.3 spec/models/spree/calculator_spec.rb
solidus_core-2.10.2 spec/models/spree/calculator_spec.rb
solidus_core-2.9.6 spec/models/spree/calculator_spec.rb
solidus_core-2.8.6 spec/models/spree/calculator_spec.rb
solidus_core-2.10.1 spec/models/spree/calculator_spec.rb
solidus_core-2.9.5 spec/models/spree/calculator_spec.rb
solidus_core-2.10.0 spec/models/spree/calculator_spec.rb
solidus_core-2.9.4 spec/models/spree/calculator_spec.rb
solidus_core-2.6.6 spec/models/spree/calculator_spec.rb
solidus_core-2.7.4 spec/models/spree/calculator_spec.rb
solidus_core-2.8.5 spec/models/spree/calculator_spec.rb
solidus_core-2.9.3 spec/models/spree/calculator_spec.rb
solidus_core-2.9.2 spec/models/spree/calculator_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/calculator_spec.rb
solidus_core-2.7.3 spec/models/spree/calculator_spec.rb
solidus_core-2.6.5 spec/models/spree/calculator_spec.rb
solidus_core-2.9.1 spec/models/spree/calculator_spec.rb
solidus_core-2.9.0 spec/models/spree/calculator_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/calculator_spec.rb