Skip to content

Commit afd4daa

Browse files
nmburganclaude
andcommitted
Migrate bundled module specs from mocha to rspec-mocks
The ci:modules rake task had silently been a no-op since commit 722532c removed the per-module Rakefiles in July 2025. It iterated each bundled module directory and shelled out to rake spec, which walked up to the top level Rakefile and errored out because no spec task was defined there. Rewrite ci:modules to invoke rspec directly, update each module spec_helper to configure rspec-puppet with a proper module_path, migrate ~420 mocha-style call sites to rspec-mocks, refactor around(:each) + Puppet.override wrappers into before(:each)/after(:each) push_context pairs (rspec-mocks rejects double setup from around hooks running before example.run), and drop mocha from the Gemfile. Fix test bugs that were silently broken while ci:modules was a no-op: rename pcp:// test targets to remote:// (pcp transport was removed from openvox), delete two tests that exercised a dead pcp-only code path in run_task / run_task_with, correct inventory.get_target typos to get_targets, fix wait_until_available argument expectation, and require bolt/target in the prompt spec_helper so Puppet type signatures load. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: nmburgan <13688219+nmburgan@users.noreply.github.com>
1 parent 732ebf1 commit afd4daa

64 files changed

Lines changed: 1101 additions & 913 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ gem "paint", "~> 2.2"
3131

3232
group(:test) do
3333
gem "beaker-hostgenerator"
34-
gem "mocha", '>= 1.4.0', '< 4'
3534
gem "rack-test", '>= 1', '< 3'
3635
gem 'rspec-github', require: false
36+
gem 'rspec-puppet', '>= 5', require: false
37+
gem 'puppet_fixtures', '>= 0.1', '< 3', require: false
3738
end
3839

3940
group(:release, optional: true) do

bolt-modules/boltlib/spec/functions/add_facts_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
require 'bolt/inventory'
66

77
describe 'add_facts' do
8-
include PuppetlabsSpec::Fixtures
8+
include SpecFixtures
99

1010
let(:executor) { Bolt::Executor.new }
1111
let(:inventory) { Bolt::Inventory.empty }
1212
let(:target) { inventory.get_target('example') }
1313
let(:tasks_enabled) { true }
1414

15-
around(:each) do |example|
15+
before(:each) do
1616
Puppet[:tasks] = tasks_enabled
17-
Puppet.override(bolt_executor: executor, bolt_inventory: inventory) do
18-
example.run
19-
end
17+
Puppet.push_context(bolt_executor: executor, bolt_inventory: inventory)
18+
end
19+
20+
after(:each) do
21+
Puppet.pop_context
2022
end
2123

2224
it 'should set a fact on a target' do
@@ -32,7 +34,7 @@
3234
end
3335

3436
it 'reports the call to analytics' do
35-
executor.expects(:report_function_call).with('add_facts')
37+
expect(executor).to receive(:report_function_call).with('add_facts')
3638
is_expected.to run.with_params(target, {})
3739
end
3840

bolt-modules/boltlib/spec/functions/add_to_group_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
require 'bolt/inventory'
55

66
describe 'add_to_group' do
7-
include PuppetlabsSpec::Fixtures
7+
include SpecFixtures
88

99
let(:executor) { Bolt::Executor.new }
1010
let(:inventory) { Bolt::Inventory.empty }
1111
let(:target) { inventory.get_target('example') }
1212
let(:group) { 'all' }
1313
let(:tasks_enabled) { true }
1414

15-
around(:each) do |example|
15+
before(:each) do
1616
Puppet[:tasks] = tasks_enabled
17-
Puppet.override(bolt_executor: executor, bolt_inventory: inventory) do
18-
example.run
19-
end
17+
Puppet.push_context(bolt_executor: executor, bolt_inventory: inventory)
18+
end
19+
20+
after(:each) do
21+
Puppet.pop_context
2022
end
2123

2224
it 'should add a target to group' do
@@ -31,7 +33,7 @@
3133
end
3234

3335
it 'reports the call to analytics' do
34-
executor.expects(:report_function_call).with('add_to_group')
36+
expect(executor).to receive(:report_function_call).with('add_to_group')
3537
is_expected.to run.with_params(target, group)
3638
end
3739

0 commit comments

Comments
 (0)