Skip to content

Commit b877055

Browse files
committed
Support single-key hashes as inputs to configure
1 parent 83ffd53 commit b877055

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/cli/mastermind/configuration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ def plan_file(*files)
180180
# Add arbitrary configuration attributes to the configuration object.
181181
# Use this to add plan specific configuration options.
182182
def configure(attribute, value=nil, &block)
183+
attribute, value = attribute.first if attribute.is_a? Hash
184+
183185
Configuration.add_attribute(attribute)
184186
@config.public_send "#{attribute}=", value, &block
185187
end

spec/cli/mastermind/configuration_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,23 @@
3737
end
3838
end
3939
end
40+
41+
context 'DSL' do
42+
let(:config) { described_class.new }
43+
let(:dsl) { described_class::DSL.new config, '' }
44+
45+
context '#configure' do
46+
it 'creates a method on the configuration object' do
47+
dsl.configure(:test)
48+
49+
expect(config).to respond_to(:test)
50+
end
51+
52+
it 'accepts a hash as the key: value' do
53+
dsl.configure(test: 'foo')
54+
55+
expect(config.test).to eq 'foo'
56+
end
57+
end
58+
end
4059
end

0 commit comments

Comments
 (0)