Sha256: 0a7c3e9414bc570d46f4081af070ce98ea5bf8c16a5fbf8ff168ef3603fe52d3

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

describe '.values_file / #load_from_self (without __END__ data) (JSON format)' do
  describe 'DSL macros' do
    context 'strict behavior' do
      let(:config_klass) do
        Class.new(Qonfig::DataSet) do
          values_file :self, format: :json, strict: true
          setting :user, 'D@iVeR'
        end
      end

      specify 'fails with Qonfig::SelfDataNotFoundError' do
        expect { config_klass.new }.to raise_error(Qonfig::SelfDataNotFoundError)
      end
    end

    context 'non-strict behavior (default)' do
      let(:config_klass) do
        Class.new(Qonfig::DataSet) do
          values_file :self, format: :json
          setting :user, 'D@iVeR'
        end
      end

      specify 'config instantiation works well :)' do
        config = nil
        expect { config = config_klass.new }.not_to raise_error
        expect(config.settings.user).to eq('D@iVeR')
      end
    end
  end

  describe 'Instance method' do
    context 'strict behavior (default)' do
      let(:config_klass) do
        Class.new(Qonfig::DataSet) { setting :user, 'D@iVeR' }
      end

      specify 'fails with Qonfig::SelfDataNotFoundError' do
        config = config_klass.new

        expect do
          config.load_from_self(format: :json, strict: true)
        end.to raise_error(Qonfig::SelfDataNotFoundError)
      end
    end

    context 'non-strict behavior' do
      let(:config_klass) do
        Class.new(Qonfig::DataSet) { setting :user, 'D@iVeR' }
      end

      specify 'no errors :)' do
        config = config_klass.new

        expect do
          config.load_from_self(format: :json, strict: false)
        end.not_to raise_error

        expect(config.settings.user).to eq('D@iVeR')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qonfig-0.28.0 spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb
qonfig-0.27.0 spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb
qonfig-0.26.0 spec/features/load_setting_values_from_file/load_from_self/json_format/without_end_data_spec.rb