Skip to content

Commit acda807

Browse files
committed
(BOLT-1585) Ruby 3 compatability for separation of positional vs named args
Changes to the way keyword and positional arguments are handled in ruby 3 are extensively documented in this post: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ This commit updates bolt code to explicitly make the distinction between keyword and positional parameters. This change should retain compatability between both ruby 2 and 3.
1 parent e04a399 commit acda807

File tree

8 files changed

+12
-12
lines changed

8 files changed

+12
-12
lines changed

lib/bolt/result.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def self._pcore_init_from_hash
128128

129129
def _pcore_init_from_hash(init_hash)
130130
opts = init_hash.reject { |k, _v| k == 'target' }
131-
initialize(init_hash['target'], opts.transform_keys(&:to_sym))
131+
initialize(init_hash['target'], **opts.transform_keys(&:to_sym))
132132
end
133133

134134
def _pcore_init_hash

lib/bolt_spec/plans/action_stubs.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def default_for(target)
9393
when Bolt::Error
9494
Bolt::Result.from_exception(target, @data[:default])
9595
when Hash
96-
result_for(target, Bolt::Util.walk_keys(@data[:default], &:to_sym))
96+
result_for(target, **Bolt::Util.walk_keys(@data[:default], &:to_sym))
9797
else
9898
raise 'Default result must be a Hash'
9999
end
@@ -156,7 +156,7 @@ def return_for_targets(data)
156156
# set the inventory from the BoltSpec::Plans, otherwise if we try to convert
157157
# this target to a string, it will fail to string conversion because the
158158
# inventory is nil
159-
hsh[target] = result_for(Bolt::Target.new(target, @inventory), Bolt::Util.walk_keys(result, &:to_sym))
159+
hsh[target] = result_for(Bolt::Target.new(target, @inventory), **Bolt::Util.walk_keys(result, &:to_sym))
160160
end
161161
raise "Cannot set return values and return block." if @return_block
162162
@data_set = true

lib/bolt_spec/plans/action_stubs/download_stub.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def parameters
4141
@invocation[:options]
4242
end
4343

44-
def result_for(_target, _data)
44+
def result_for(_target, **_data)
4545
raise 'Download result cannot be changed'
4646
end
4747

lib/bolt_spec/plans/action_stubs/plan_stub.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def parameters
3030
end
3131

3232
# Allow any data.
33-
def result_for(_target, data)
33+
def result_for(_target, **data)
3434
Bolt::PlanResult.new(Bolt::Util.walk_keys(data, &:to_s), 'success')
3535
end
3636

lib/bolt_spec/plans/action_stubs/task_stub.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def parameters
3737
end
3838

3939
# Allow any data.
40-
def result_for(target, data)
40+
def result_for(target, **data)
4141
Bolt::Result.new(target, value: Bolt::Util.walk_keys(data, &:to_s))
4242
end
4343

lib/bolt_spec/plans/action_stubs/upload_stub.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def parameters
4040
@invocation[:options]
4141
end
4242

43-
def result_for(_target, _data)
43+
def result_for(_target, **_data)
4444
raise 'Upload result cannot be changed'
4545
end
4646

lib/bolt_spec/plans/mock_executor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def stub_apply
210210
@allow_apply = true
211211
end
212212

213-
def wait_until_available(targets, _options)
213+
def wait_until_available(targets, **_options)
214214
Bolt::ResultSet.new(targets.map { |target| Bolt::Result.new(target) })
215215
end
216216

spec/bolt_spec/run_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
end
2929

3030
it 'should accept _catch_errors' do
31-
result = run_task('sample::echo', 'non_existent_node', '_catch_errors' => true)
31+
result = run_task('sample::echo', 'non_existent_node', { '_catch_errors' => true })
3232

3333
expect(result[0]['status']).to eq('failure')
3434
expect(result[0]['value']['_error']['kind']).to eq('puppetlabs.tasks/connect-error')
@@ -85,20 +85,20 @@
8585

8686
describe 'run_plan' do
8787
it 'should run a plan' do
88-
result = run_plan('sample::single_task', 'nodes' => 'ssh')
88+
result = run_plan('sample::single_task', { 'nodes' => 'ssh' })
8989
expect(result['status']).to eq('success')
9090
data = result['value'][0]
9191
expect(data['status']).to eq('success')
9292
end
9393

9494
it 'should return a failure' do
95-
result = run_plan('error::run_fail', 'targets' => 'ssh')
95+
result = run_plan('error::run_fail', { 'targets' => 'ssh' })
9696
expect(result['status']).to eq('failure')
9797
expect(result['value']['kind']).to eq('bolt/run-failure')
9898
end
9999

100100
it 'runs a plan that downloads a file' do
101-
result = run_plan('sample::download_file', 'nodes' => 'ssh')
101+
result = run_plan('sample::download_file', { 'nodes' => 'ssh' })
102102
expect(result['status']).to eq('success')
103103
data = result['value'][0]
104104
expect(data['value']['path']).to match(%r{^/tmp/})

0 commit comments

Comments
 (0)