Sha256: 7f38c6e8a8d6fd96b5e937aaa48171f91bcea24fade65ba6b885902cbac85068

Contents?: true

Size: 1.49 KB

Versions: 128

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/options_consumer'

RSpec.describe ::EacRubyUtils::OptionsConsumer do
  context 'instance created with some data' do
    subject(:instance) { described_class.new(a: 'a_value', b: 'b_value', c: 'c_value') }

    it 'left data should be Hash' do
      expect(instance.left_data).to be_a(::Hash)
    end

    it 'left data should be not empty' do
      expect { instance.validate }.to raise_error(::StandardError)
    end

    it 'parses args' do
      expect(instance.left_data).to eq({ a: 'a_value', b: 'b_value', c: 'c_value' }
          .with_indifferent_access)
      expect(instance.consume(:a)).to eq('a_value')
      expect(instance.left_data).to eq({ b: 'b_value', c: 'c_value' }.with_indifferent_access)
      expect(instance.consume(:c)).to eq('c_value')
      expect(instance.left_data).to eq({ b: 'b_value' }.with_indifferent_access)
      expect(instance.consume(:b)).to eq('b_value')
      expect(instance.left_data).to eq({}.with_indifferent_access)
      instance.validate
    end

    it 'raises if validate has left data' do
      expect(instance.left_data.empty?).to eq(false)
    end
  end

  describe '#consume_all' do
    subject(:instance) { described_class.new(a: 'a_value', b: 'b_value', c: 'c_value') }

    it 'return all options in arguments' do
      a, b, c, d = instance.consume_all(:a, :b, :c, :d)
      expect(a).to eq('a_value')
      expect(b).to eq('b_value')
      expect(c).to eq('c_value')
      expect(d).to eq(nil)
    end
  end
end

Version data entries

128 entries across 128 versions & 2 rubygems

Version Path
avm-tools-0.55.0 vendor/gems/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
avm-tools-0.54.2 vendor/gems/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
avm-tools-0.54.1 vendor/gems/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
avm-tools-0.54.0 vendor/gems/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
avm-tools-0.53.0 vendor/gems/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
avm-tools-0.52.0 vendor/gems/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
avm-tools-0.51.0 vendor/gems/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb
ehbrs-tools-0.12.0 vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/options_consumer_spec.rb