Skip to content

Commit

Permalink
Convert keys to symbols when initializing a new ConfigSL::Config.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesiarmes committed Sep 5, 2024
1 parent 4f83875 commit 29535e4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][changelog], and this project adheres
to [Semantic Versioning][versioning].
ß

## [Unreleased]

### Fixed

- Subclasses of `ConfigSL::Config` initialized with sting keys no longer raise
an error.

## 1.0.0

Initial release.
Expand Down
2 changes: 1 addition & 1 deletion lib/configsl/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Config

def initialize(params = {})
params.each do |name, value|
set_value(name, value)
set_value(name.to_sym, value)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/support/configs.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative 'configs/config_spec_config'
require_relative 'configs/dsl_spec_config'
require_relative 'configs/format_spec_config'
require_relative 'configs/from_environment_spec_config'
Expand Down
7 changes: 7 additions & 0 deletions spec/support/configs/config_spec_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ConfigSpecConfig < ConfigSL::Config
option :default, type: String, default: 'rspec-default'
option :optional, type: String
option :required, type: String, required: true
end
24 changes: 24 additions & 0 deletions spec/unit/configsl/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

RSpec.describe ConfigSL::Config do
subject(:config) { ConfigSpecConfig }

describe '#initialize' do
it 'raises an error for unknown options' do
expect { config.new(unknown: 'rspec') }.to \
raise_error(ConfigSL::InvalidOptionError)
end

it 'sets values for hash keys' do
instance = config.new(required: 'rspec')

expect(instance.required).to eq('rspec')
end

it 'sets values for string keys' do
instance = config.new('required' => 'rspec')

expect(instance.required).to eq('rspec')
end
end
end

0 comments on commit 29535e4

Please sign in to comment.