Skip to content

Commit fb0497d

Browse files
authored
Merge pull request #317 from mhashizume/PA-5641/main/ruby-32
(PA-5641) Update rspec tests with modern Ruby
2 parents edbf55a + 9e595f6 commit fb0497d

File tree

8 files changed

+30
-29
lines changed

8 files changed

+30
-29
lines changed

.github/workflows/rspec_tests.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,28 @@ permissions:
1111

1212
jobs:
1313
rspec_tests:
14-
name: RSpec (Ruby ${{ matrix.ruby }}, Puppet ${{ matrix.puppet_version }})
14+
name: Puppet ${{ matrix.cfg.puppet_version }}, Ruby ${{ matrix.cfg.ruby }}
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
ruby: [ '2.5', '2.7', 'jruby-9.2.17.0' ]
19-
puppet_version: [ '~> 6.29', '~> 7.22' ]
18+
cfg:
19+
- {puppet_version: '7', ruby: '2.7'}
20+
- {puppet_version: '7', ruby: 'jruby-9.3.7.0'}
21+
- {puppet_version: '8', ruby: '3.2'}
22+
- {puppet_version: '8', ruby: 'jruby-9.4.2.0'}
2023
env:
21-
PUPPET_GEM_VERSION: ${{ matrix.puppet_version }}
24+
PUPPET_GEM_VERSION: ~> ${{ matrix.cfg.puppet_version }}
2225
steps:
2326
- name: Checkout current PR
2427
uses: actions/checkout@v3
2528
with:
2629
fetch-depth: 0
27-
- name: Install Ruby version ${{ matrix.ruby }}
30+
- name: Install Ruby version ${{ matrix.cfg.ruby }}
2831
uses: ruby/setup-ruby@v1
2932
with:
30-
ruby-version: ${{ matrix.ruby }}
33+
ruby-version: ${{ matrix.cfg.ruby }}
3134
- name: Update rubygems and install gems
3235
run: |
33-
gem update --system 3.3.26 --silent --no-document
3436
bundle config set without development
3537
bundle install --jobs 4 --retry 3
3638
- run: bundle exec rake

.rubocop.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ Lint/NestedMethodDefinition:
121121
RSpec/MessageSpies:
122122
Enabled: false
123123

124-
# If neighbouring parameters are both hashes, it helps to have braces round both.
124+
# This cop causes issues on our current version of Rubocop (0.57.2) and newer (>= 3.0) Rubies because of keyword arguments.
125125
Style/BracesAroundHashParameters:
126-
Exclude:
127-
- 'spec/puppet/resource_api/base_context_spec.rb'
126+
Enabled: false
128127

129128
# requires 2.3's squiggly HEREDOC support, which we can't use, yet
130129
# see http://www.virtuouscode.com/2016/01/06/about-the-ruby-squiggly-heredoc-syntax/

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Puppet::ResourceApi [![TravisCI Build Status](https://travis-ci.org/puppetlabs/puppet-resource_api.svg?branch=main)](https://travis-ci.org/puppetlabs/puppet-resource_api) [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/8o9s1ax0hs8lm5fd/branch/main?svg=true)](https://ci.appveyor.com/project/puppetlabs/puppet-resource-api/branch/main) [![codecov](https://codecov.io/gh/puppetlabs/puppet-resource_api/branch/main/graph/badge.svg)](https://codecov.io/gh/puppetlabs/puppet-resource_api)
1+
# Puppet::ResourceApi [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/8o9s1ax0hs8lm5fd/branch/main?svg=true)](https://ci.appveyor.com/project/puppetlabs/puppet-resource-api/branch/main) [![codecov](https://codecov.io/gh/puppetlabs/puppet-resource_api/branch/main/graph/badge.svg)](https://codecov.io/gh/puppetlabs/puppet-resource_api)
22

3-
This is an implementation of the [Resource API specification](https://github.com/puppetlabs/puppet-specifications/blob/main/language/resource-api/README.md).
3+
This is an implementation of the [Resource API specification](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md).
44

55
Find a working example of a new-style providers in the [Palo Alto Firewall module](https://github.com/puppetlabs/puppetlabs-panos/):
66
* [Type](https://github.com/puppetlabs/puppetlabs-panos/blob/main/lib/puppet/type/panos_address.rb)
@@ -15,18 +15,18 @@ Find a working example of a new-style providers in the [Palo Alto Firewall modul
1515
* The [Resource API specs](https://github.com/puppetlabs/puppet-specifications/blob/master/language/resource-api/README.md) describes details of all the capabilities of this gem.
1616
* The [puppetlabs-hue module](https://github.com/puppetlabs/puppetlabs-hue) is a very simple example for using the Resource API for remote resources.
1717
* The [meraki module](https://github.com/meraki/puppet-module) is a full example for using the Resource API for remote resources.
18-
* This [Introduction to Testing Puppet Modules](https://www.netways.de/index.php?id=3445#c44135) talk describes rspec usage in more detail.
19-
* The [RSpec docs](https://relishapp.com/rspec) provide an overview of the capabilities of rspec.
18+
* This [Introduction to Testing Puppet Modules](https://www.youtube.com/watch?v=GgNrxLfoDF8) talk describes rspec usage in more detail.
19+
* The [RSpec docs](https://rspec.info/documentation/) provide an overview of the capabilities of rspec.
2020
* Read [betterspecs](http://www.betterspecs.org/) for general guidelines on what is considered good specs.
2121

2222

2323
## Deployment
2424

25-
The `puppet-resource_api` gem is part of the [Puppet 6 Platform](https://puppet.com/blog/introducing-puppet-6). With older versions of Puppet, you can use the [puppetlabs-resource_api module](https://forge.puppet.com/puppetlabs/resource_api) to install the gem on your servers and agents.
25+
The `puppet-resource_api` gem is part of Puppet from version 6 onward.
2626

2727

2828
## Contributing
29-
We are always welcoming bug reports and pull requests on the Resource API, so that we can continue to improve it to the best of our ability. If you would like to contribute, [have a look at our GitHub](https://github.com/puppetlabs/puppet-resource_api) and the [Resource API Backlog](https://github.com/puppetlabs/puppet-resource_api/projects/1).
29+
We welcome bug reports and pull requests on the Resource API so that we can continue to improve it to the best of our ability. If you would like to contribute, [have a look at our GitHub](https://github.com/puppetlabs/puppet-resource_api) and the [Resource API Backlog](https://github.com/puppetlabs/puppet-resource_api/projects/1).
3030

3131

3232
## Known Issues

lib/puppet/resource_api/base_context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def failing(titles, message: 'Failing')
9090
end
9191
end
9292

93-
def processing(title, is, should, message: 'Processing')
93+
def processing(title, is, should, message = 'Processing')
9494
raise "#{__method__} only accepts a single resource title" if title.respond_to?(:each)
9595
start_time = Time.now
9696
setup_context(title, message)

lib/puppet/resource_api/data_type_handling.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def self.try_mungify(type, value, error_msg_prefix)
8686
when Puppet::Pops::Types::PIntegerType,
8787
Puppet::Pops::Types::PFloatType,
8888
Puppet::Pops::Types::PNumericType
89-
if value =~ %r{^-?\d+$} || value =~ Puppet::Pops::Patterns::NUMERIC
89+
if value.is_a?(String) && (value.match?(%r{^-?\d+$}) || value.match?(Puppet::Pops::Patterns::NUMERIC))
9090
value = Puppet::Pops::Utils.to_n(value)
9191
end
9292
when Puppet::Pops::Types::PEnumType,

spec/puppet/resource_api/base_context_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def send_log(log, msg)
362362

363363
describe '#feature_support?' do
364364
it {
365-
expect(Puppet::Util::Log).to receive(:create).with(level: :warning, source: 'Puppet', message: match(%r{context.feature_support\? is deprecated. Please use context.type.feature\? instead\.}))
365+
expect(Puppet::Util::Log).to receive(:create).with({ level: :warning, source: 'Puppet', message: start_with('context.feature_support? is deprecated. Please use context.type.feature? instead.') }) # rubocop:disable Metrics/LineLength
366366
context.feature_support?('anything')
367367
}
368368
end

spec/puppet/resource_api/simple_provider_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def delete(context, _name); end
259259
end
260260

261261
before(:each) do
262-
allow(context).to receive(:creating).with(name1: 'value1', name2: 'value2').and_yield
262+
allow(context).to receive(:creating).with({ name1: 'value1', name2: 'value2' }).and_yield
263263
allow(type_def).to receive(:feature?).with('simple_get_filter').and_return(true)
264264
allow(type_def).to receive(:namevars).and_return([:name1, :name2])
265265
allow(type_def).to receive(:check_schema)

spec/puppet/resource_api/transport_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def change_environment(name = nil)
188188

189189
context 'when the transport file does not exist' do
190190
it 'throws a LoadError' do
191-
expect(described_class).to receive(:validate).with(name, host: 'example.com')
191+
expect(described_class).to receive(:validate).with(name, { host: 'example.com' })
192192
expect { described_class.connect(name, host: 'example.com') }.to raise_error LoadError, %r{(no such file to load|cannot load such file) -- puppet/transport/test_target}
193193
end
194194
end
@@ -198,10 +198,10 @@ def change_environment(name = nil)
198198
it 'throws a NameError' do
199199
described_class.register(schema)
200200

201-
expect(described_class).to receive(:validate).with(name, host: 'example.com')
201+
expect(described_class).to receive(:validate).with(name, { host: 'example.com' })
202202
expect(described_class).to receive(:require).with('puppet/transport/test_target')
203-
expect { described_class.connect(name, host: 'example.com') }.to raise_error NameError,
204-
%r{uninitialized constant (Puppet::Transport|TestTarget)}
203+
expect { described_class.connect(name, { host: 'example.com' }) }.to raise_error NameError,
204+
%r{uninitialized constant (Puppet::Transport|TestTarget)}
205205
end
206206
end
207207

@@ -214,13 +214,13 @@ def change_environment(name = nil)
214214

215215
allow(described_class).to receive(:require).with('puppet/resource_api/puppet_context').and_call_original
216216
expect(described_class).to receive(:require).with('puppet/transport/test_target')
217-
expect(described_class).to receive(:validate).with(name, host: 'example.com')
217+
expect(described_class).to receive(:validate).with(name, { host: 'example.com' })
218218
expect(Puppet::ResourceApi::PuppetContext).to receive(:new).with(kind_of(Puppet::ResourceApi::TransportSchemaDef)).and_return(context)
219219

220220
stub_const('Puppet::Transport::TestTarget', test_target)
221-
expect(test_target).to receive(:new).with(context, host: 'example.com')
221+
expect(test_target).to receive(:new).with(context, { host: 'example.com' })
222222

223-
described_class.connect(name, host: 'example.com')
223+
described_class.connect(name, { host: 'example.com' })
224224
end
225225
end
226226
end
@@ -303,7 +303,7 @@ class Wibble; end
303303

304304
it 'cleans the connection_info' do
305305
expect(schema_def).to receive(:check_schema).with({ host: 'host value', foo: 'foo value' }, kind_of(String)).and_return(nil)
306-
expect(schema_def).to receive(:validate).with(host: 'host value', foo: 'foo value').and_return(nil)
306+
expect(schema_def).to receive(:validate).with({ host: 'host value', foo: 'foo value' }).and_return(nil)
307307

308308
expect(context).to receive(:debug).with('Discarding bolt metaparameter: query')
309309
expect(context).to receive(:debug).with('Discarding bolt metaparameter: remote-transport')
@@ -325,7 +325,7 @@ class Wibble; end
325325

326326
it 'sets defaults in the connection info' do
327327
expect(schema_def).to receive(:check_schema).with({ host: 'host value', port: 443 }, kind_of(String)).and_return(nil)
328-
expect(schema_def).to receive(:validate).with(host: 'host value', port: 443).and_return(nil)
328+
expect(schema_def).to receive(:validate).with({ host: 'host value', port: 443 }).and_return(nil)
329329

330330
expect(context).to receive(:debug).with('Using default value for attribute: port, value: 443')
331331
described_class.send :validate, 'validate', host: 'host value'

0 commit comments

Comments
 (0)