Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert keys to symbols when initializing a new ConfigSL::Config. #1

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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