Sha256: 5f0c34b84c736363d85a9383784b4c490e8d6edb1be6c4568204232f9e7fba38

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe SolidusVolumePricing::RangeFromString do
  describe 'new' do
    subject(:range) { described_class.new(argument).to_range }

    context 'with a string with two dots' do
      let(:argument) { '1..2' }

      it { is_expected.to eq(1..2) }
    end

    context 'with a string with two dots and parens' do
      let(:argument) { '(1..2)' }

      it { is_expected.to eq(1..2) }
    end

    context 'with a string with three dots' do
      let(:argument) { '1...2' }

      it { is_expected.to eq(1...2) }
    end

    context 'with a string with three dots and parens' do
      let(:argument) { '(1...2)' }

      it { is_expected.to eq(1...2) }
    end

    context 'with an open-ended string like #{x}+' do
      let(:argument) { '10+' }

      it { is_expected.to eq(10..Float::INFINITY) }
    end

    context 'with an open-ended string like #{x}+ and parens' do
      let(:argument) { '(10+)' }

      it { is_expected.to eq(10..Float::INFINITY) }
    end

    context 'with invalid input' do
      let(:argument) { 'system("rm -rf /*")' }

      it do
        expect { subject }.to raise_error(ArgumentError)
      end
    end

    context 'with invalid input' do
      let(:argument) { '1..3; puts "Do not run Ruby Code"' }

      it do
        expect { subject }.to raise_error(ArgumentError)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_volume_pricing-1.1.0 spec/lib/solidus_volume_pricing/range_from_string_spec.rb
solidus_volume_pricing-1.0.0 spec/lib/solidus_volume_pricing/range_from_string_spec.rb