Skip to content

Commit 595db14

Browse files
authored
refactor: change from mocha to rspec-mocks voxpupuli#514
2 parents 0b880ce + d1daa35 commit 595db14

21 files changed

+247
-225
lines changed

.rubocop_todo.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
2-
# `rubocop --auto-gen-config`
3-
# on 2024-05-18 22:27:55 UTC using RuboCop version 1.50.2.
2+
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
3+
# using RuboCop version 1.50.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -16,6 +16,12 @@ RSpec/BeEq:
1616
- 'spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb'
1717
- 'spec/unit/puppet/type/rabbitmq_user_permissions_spec.rb'
1818

19+
# Offense count: 185
20+
# Configuration parameters: .
21+
# SupportedStyles: have_received, receive
22+
RSpec/MessageSpies:
23+
EnforcedStyle: receive
24+
1925
# Offense count: 3
2026
RSpec/PendingWithoutReason:
2127
Exclude:
@@ -30,3 +36,22 @@ RSpec/RepeatedExampleGroupBody:
3036
RSpec/RepeatedExampleGroupDescription:
3137
Exclude:
3238
- 'spec/classes/rabbitmq_spec.rb'
39+
40+
# Offense count: 125
41+
RSpec/StubbedMock:
42+
Exclude:
43+
- 'spec/unit/facter/util/fact_rabbitmq_clustername_spec.rb'
44+
- 'spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb'
45+
- 'spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb'
46+
- 'spec/unit/facter/util/fact_rabbitmq_version_spec.rb'
47+
- 'spec/unit/puppet/provider/rabbitmq_binding/rabbitmqadmin_spec.rb'
48+
- 'spec/unit/puppet/provider/rabbitmq_cli_spec.rb'
49+
- 'spec/unit/puppet/provider/rabbitmq_cluster/rabbitmqctl_spec.rb'
50+
- 'spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb'
51+
- 'spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_federation_spec.rb'
52+
- 'spec/unit/puppet/provider/rabbitmq_parameter/rabbitmqctl_spec.rb'
53+
- 'spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb'
54+
- 'spec/unit/puppet/provider/rabbitmq_policy/rabbitmqctl_spec.rb'
55+
- 'spec/unit/puppet/provider/rabbitmq_queue/rabbitmqadmin_spec.rb'
56+
- 'spec/unit/puppet/provider/rabbitmq_user_permissions/rabbitmqctl_spec.rb'
57+
- 'spec/unit/puppet/provider/rabbitmq_vhost/rabbitmqctl_spec.rb'

.sync.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
---
22
spec/spec_helper.rb:
33
facterdb_string_keys: true
4-
mock_with: ':mocha'
54
spec_overrides: "require 'spec_helper_local'"
65
.puppet-lint.rc:
76
enabled_lint_checks:
87
- parameter_documentation
98
- parameter_types
10-
Gemfile:
11-
optional:
12-
':test':
13-
- gem: 'mocha'

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
66
group :test do
77
gem 'voxpupuli-test', '~> 11.0', :require => false
88
gem 'puppet_metadata', '~> 5.0', :require => false
9-
gem 'mocha', :require => false
109
end
1110

1211
group :development do

spec/spec_helper.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
RSpec.configure do |c|
1313
c.facterdb_string_keys = true
14-
c.mock_with :mocha
1514
end
1615

1716
add_mocked_facts!

spec/unit/facter/util/fact_erl_ssl_path_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88
describe 'erl_ssl_path' do
99
context 'with valid value' do
1010
it do
11-
Facter::Util::Resolution.expects(:which).with('erl').returns(true)
12-
Facter::Core::Execution.expects(:execute).with("erl -eval 'io:format(\"~p\", [code:lib_dir(ssl, ebin)]),halt().' -noshell").returns('"/usr/lib64/erlang/lib/ssl-5.3.3/ebin"')
11+
allow(Facter::Util::Resolution).to receive(:which).with('erl').and_return(true)
12+
allow(Facter::Core::Execution).to receive(:execute).with("erl -eval 'io:format(\"~p\", [code:lib_dir(ssl, ebin)]),halt().' -noshell").and_return('"/usr/lib64/erlang/lib/ssl-5.3.3/ebin"')
1313
expect(Facter.fact(:erl_ssl_path).value).to eq('/usr/lib64/erlang/lib/ssl-5.3.3/ebin')
1414
end
1515
end
1616

1717
context 'with error message' do
1818
it do
19-
Facter::Util::Resolution.expects(:which).with('erl').returns(true)
20-
Facter::Core::Execution.expects(:execute).with("erl -eval 'io:format(\"~p\", [code:lib_dir(ssl, ebin)]),halt().' -noshell").returns('{error,bad_name}')
19+
allow(Facter::Util::Resolution).to receive(:which).with('erl').and_return(true)
20+
allow(Facter::Core::Execution).to receive(:execute).with("erl -eval 'io:format(\"~p\", [code:lib_dir(ssl, ebin)]),halt().' -noshell").and_return('{error,bad_name}')
2121
expect(Facter.fact(:erl_ssl_path).value).to be_nil
2222
end
2323
end
2424

2525
context 'with erl not present' do
2626
it do
27-
Facter::Util::Resolution.expects(:which).with('erl').returns(false)
27+
allow(Facter::Util::Resolution).to receive(:which).with('erl').and_return(false)
2828
expect(Facter.fact(:erl_ssl_path).value).to be_nil
2929
end
3030
end

spec/unit/facter/util/fact_rabbitmq_clustername_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@
1010
describe 'rabbitmq_clusternam' do
1111
context 'with value' do
1212
it do
13-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
14-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns(' {cluster_name,<<"monty">>},')
13+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
14+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl -q cluster_status 2>&1').and_return(' {cluster_name,<<"monty">>},')
1515
expect(Facter.fact(:rabbitmq_clustername).value).to eq('monty')
1616
end
1717
end
1818

1919
context 'with dashes in hostname' do
2020
it do
21-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
22-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns('Cluster name: rabbit-1')
21+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
22+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl -q cluster_status 2>&1').and_return('Cluster name: rabbit-1')
2323
expect(Facter.fact(:rabbitmq_clustername).value).to eq('rabbit-1')
2424
end
2525
end
2626

2727
context 'with dashes in clustername/hostname' do
2828
it do
29-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
30-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns(' {cluster_name,<<"monty-python@rabbit-1">>},')
29+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
30+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl -q cluster_status 2>&1').and_return(' {cluster_name,<<"monty-python@rabbit-1">>},')
3131
expect(Facter.fact(:rabbitmq_clustername).value).to eq('monty-python@rabbit-1')
3232
end
3333
end
3434

3535
context 'with quotes around node name' do
3636
it do
37-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
38-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns("monty\npython\nCluster name: 'monty@rabbit-1'\nend\nof\nfile")
37+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
38+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl -q cluster_status 2>&1').and_return("monty\npython\nCluster name: 'monty@rabbit-1'\nend\nof\nfile")
3939
expect(Facter.fact(:rabbitmq_clustername).value).to eq("'monty@rabbit-1'")
4040
end
4141
end
@@ -63,15 +63,15 @@
6363
- cookie hash: 6WdP0nl6d3HYqA5vTKMkIg==
6464
6565
EOS
66-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
67-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl -q cluster_status 2>&1').returns(error_string)
66+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
67+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl -q cluster_status 2>&1').and_return(error_string)
6868
expect(Facter.fact(:rabbitmq_clustername).value).to be_nil
6969
end
7070
end
7171

7272
context 'rabbitmqctl is not in path' do
7373
it do
74-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(false)
74+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(false)
7575
expect(Facter.fact(:rabbitmq_clustername).value).to be_nil
7676
end
7777
end

spec/unit/facter/util/fact_rabbitmq_nodename_spec.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,47 @@
33
require 'spec_helper'
44

55
describe Facter::Util::Fact do
6-
before { Facter.clear }
6+
before do
7+
Facter.clear
8+
end
79

810
describe 'rabbitmq_nodename' do
911
context 'with value' do
1012
it do
11-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
12-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit1 ...')
13+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
14+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1').and_return('Status of node monty@rabbit1 ...')
1315
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit1')
1416
end
1517
end
1618

1719
context 'with dashes in hostname' do
1820
it do
19-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
20-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit-1 ...')
21+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
22+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1').and_return('Status of node monty@rabbit-1 ...')
2123
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
2224
end
2325
end
2426

2527
context 'with dashes in nodename/hostname' do
2628
it do
27-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
28-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty-python@rabbit-1 ...')
29+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
30+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1').and_return('Status of node monty-python@rabbit-1 ...')
2931
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty-python@rabbit-1')
3032
end
3133
end
3234

3335
context 'with quotes around node name' do
3436
it do
35-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
36-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node \'monty@rabbit-1\' ...')
37+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
38+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1').and_return('Status of node \'monty@rabbit-1\' ...')
3739
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
3840
end
3941
end
4042

4143
context 'without trailing points' do
4244
it do
43-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
44-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns('Status of node monty@rabbit-1')
45+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
46+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1').and_return('Status of node monty@rabbit-1')
4547
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
4648
end
4749
end
@@ -69,15 +71,15 @@
6971
- cookie hash: 6WdP0nl6d3HYqA5vTKMkIg==
7072
7173
EOS
72-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
73-
Facter::Core::Execution.expects(:execute).with('rabbitmqctl status 2>&1').returns(error_string)
74+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
75+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqctl status 2>&1').and_return(error_string)
7476
expect(Facter.fact(:rabbitmq_nodename).value).to eq('monty@rabbit-1')
7577
end
7678
end
7779

7880
context 'rabbitmqctl is not in path' do
7981
it do
80-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(false)
82+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(false)
8183
expect(Facter.fact(:rabbitmq_nodename).value).to be_nil
8284
end
8385
end

spec/unit/facter/util/fact_rabbitmq_plugins_dirs_spec.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@
33
require 'spec_helper'
44

55
describe Facter::Util::Fact do
6-
before { Facter.clear }
6+
before do
7+
Facter.clear
8+
end
79

810
describe 'rabbitmq_plugins_dirs' do
911
context 'with multiple plugins dirs' do
1012
it do
11-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
12-
Facter::Core::Execution.expects(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").returns('{ok,"/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/plugins"}')
13+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
14+
expect(Facter::Core::Execution).to receive(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").and_return('{ok,"/usr/lib/rabbitmq/plugins:/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/plugins"}')
1315
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to contain_exactly('/usr/lib/rabbitmq/plugins', '/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.10/plugins')
1416
end
1517
end
1618

1719
context 'with only 1 plugins dir' do
1820
it do
19-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(true)
20-
Facter::Core::Execution.expects(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").returns('{ok,"/usr/lib/rabbitmq/lib/rabbitmq_server-0.0.0/plugins"}')
21+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(true)
22+
expect(Facter::Core::Execution).to receive(:execute).with("rabbitmqctl eval 'application:get_env(rabbit, plugins_dir).'").and_return('{ok,"/usr/lib/rabbitmq/lib/rabbitmq_server-0.0.0/plugins"}')
2123
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to contain_exactly('/usr/lib/rabbitmq/lib/rabbitmq_server-0.0.0/plugins')
2224
end
2325
end
2426

2527
context 'rabbitmqctl is not in path' do
2628
it do
27-
Facter::Util::Resolution.expects(:which).with('rabbitmqctl').returns(false)
29+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqctl').and_return(false)
2830
expect(Facter.fact(:rabbitmq_plugins_dirs).value).to be_nil
2931
end
3032
end

spec/unit/facter/util/fact_rabbitmq_version_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
describe 'rabbitmq_version' do
1111
context 'with value' do
1212
it do
13-
Facter::Util::Resolution.expects(:which).with('rabbitmqadmin').returns(true)
14-
Facter::Core::Execution.expects(:execute).with('rabbitmqadmin --version 2>&1').returns('rabbitmqadmin 3.6.0')
13+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqadmin').and_return(true)
14+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqadmin --version 2>&1').and_return('rabbitmqadmin 3.6.0')
1515
expect(Facter.fact(:rabbitmq_version).value).to eq('3.6.0')
1616
end
1717
end
1818

1919
context 'with invalid value' do
2020
it do
21-
Facter::Util::Resolution.expects(:which).with('rabbitmqadmin').returns(true)
22-
Facter::Core::Execution.expects(:execute).with('rabbitmqadmin --version 2>&1').returns('rabbitmqadmin %%VSN%%')
21+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqadmin').and_return(true)
22+
expect(Facter::Core::Execution).to receive(:execute).with('rabbitmqadmin --version 2>&1').and_return('rabbitmqadmin %%VSN%%')
2323
expect(Facter.fact(:rabbitmq_version).value).to be_nil
2424
end
2525
end
2626

2727
context 'rabbitmqadmin is not in path' do
2828
it do
29-
Facter::Util::Resolution.expects(:which).with('rabbitmqadmin').returns(false)
29+
expect(Facter::Util::Resolution).to receive(:which).with('rabbitmqadmin').and_return(false)
3030
expect(Facter.fact(:rabbitmq_version).value).to be_nil
3131
end
3232
end

0 commit comments

Comments
 (0)