Sha256: 6b54cf0fefc0df9b650a7bded5a59f290bea3b98d0ba258a87679e0a38870cc2

Contents?: true

Size: 1.8 KB

Versions: 34

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Sinclair::Config::MethodsBuilder do
  describe '#build' do
    let(:config_class) { Class.new(Sinclair::Config) }
    let(:config)       { config_class.new }
    let(:code_block)   { proc { builder.build } }

    let(:setter_block) do
      proc do |value|
        config.instance_variable_set(:@name, value)
      end
    end

    context 'when not initializing defaults' do
      subject(:builder) { described_class.new(config_class, :name, 'password') }

      it_behaves_like 'a config methods builder adding config'

      it 'does not set a default value' do
        code_block.call

        expect(config.name).to be_nil
      end
    end

    context 'when initializing defaults' do
      subject(:builder) do
        described_class.new(
          config_class, name: 'Bobby', 'password' => 'abcdef'
        )
      end

      it_behaves_like 'a config methods builder adding config'

      it 'sets a default value' do
        code_block.call

        expect(config.name).to eq('Bobby')
      end
    end

    context 'when mixing names and hash' do
      subject(:builder) do
        described_class.new(
          config_class, :name, 'password' => 'abcdef'
        )
      end

      it_behaves_like 'a config methods builder adding config'

      it 'does not set a default value' do
        code_block.call

        expect(config.name).to be_nil
      end

      context 'when name and hash define same config' do
        subject(:builder) do
          described_class.new(
            config_class, :name, name: 'Bobby'
          )
        end

        it_behaves_like 'a config methods builder adding config'

        it 'sets a default value' do
          code_block.call

          expect(config.name).to eq('Bobby')
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

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