Sha256: cd337765a250c6f7ad6a529424ae55e4d8975edf56ad6a37d7a584b793e727f7

Contents?: true

Size: 1.45 KB

Versions: 41

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::OptionsParser do
  subject(:model) { klass.new(options) }

  let(:klass)    { described_class::Dummy }
  let(:switched) { true }
  let(:value_1)  { 'value1' }
  let(:options)  { { switch: switched, option_1: value_1, option_2: 2 } }

  it 'enables the given options to be acced' do
    expect(model.the_method).to eq('The value is value1')
  end

  context 'when changing the options' do
    let(:switched) { false }

    it 'enables the given options to be acced' do
      expect(model.the_method).to eq('The value is not value1 but 2')
    end
  end

  context 'when there is an option missing' do
    let(:options) { { option_1: 'value1', option_2: 2 } }

    it do
      expect { model.the_method }.not_to raise_error
    end

    it 'considers is to be nil' do
      expect(model.the_method).to eq('missing option')
    end
  end

  context 'when changing the options before the option call' do
    before do
      model
      options[:switch] = false
    end

    it 'does not reevaluate the options' do
      expect(model.the_method).to eq('The value is value1')
    end

    context 'when the option value is another object on its own' do
      let(:value_1) { { key: 'value' } }

      before do
        model
        options[:option_1][:key] = 100
      end

      it 'does not reevaluate the options' do
        expect(model.the_method).to eq('The value is {:key=>"value"}')
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
sinclair-2.1.1 spec/lib/sinclair/options_parser_spec.rb
sinclair-2.1.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-2.0.1 spec/lib/sinclair/options_parser_spec.rb
sinclair-2.0.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.16.3 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.16.2 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.16.1 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.16.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.15.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.14.2 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.14.1 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.14.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.13.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.12.1 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.12.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.11.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.10.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.9.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.8.0 spec/lib/sinclair/options_parser_spec.rb
sinclair-1.7.0 spec/lib/sinclair/options_parser_spec.rb