Skip to content

Commit 76a971b

Browse files
authored
Merge pull request #554 from KeithWard/convert_mocha_to_rspec
Convert unit tests to rspec rather than 'mocha'
2 parents ddb4e95 + 4b93e9d commit 76a971b

File tree

6 files changed

+43
-77
lines changed

6 files changed

+43
-77
lines changed

.sync.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77
- set: debian8-64
88
- set: debian9-64
99
- set: centos7-64
10-
spec/spec_helper.rb:
11-
mock_with: ':mocha'
1210
spec/spec_helper_acceptance.rb:
1311
unmanaged: false

spec/spec_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
# https://github.com/voxpupuli/modulesync
33
# https://github.com/voxpupuli/modulesync_config
44

5-
RSpec.configure do |c|
6-
c.mock_with :mocha
7-
end
8-
95
# puppetlabs_spec_helper will set up coverage if the env variable is set.
106
# We want to do this if lib exists and it hasn't been explicitly set.
117
ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../../lib', __FILE__))

spec/unit/facter/pip_version_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@
1414
describe 'pip_version' do
1515
context 'returns pip version when pip present' do
1616
it do
17-
Facter::Util::Resolution.stubs(:exec)
18-
Facter::Util::Resolution.expects(:which).with('pip').returns(true)
19-
Facter::Util::Resolution.expects(:exec).with('pip --version 2>&1').returns(pip_version_output)
17+
allow(Facter::Util::Resolution).to receive(:which).with('pip').and_return(true)
18+
allow(Facter::Util::Resolution).to receive(:exec).with('pip --version 2>&1').and_return(pip_version_output)
2019
expect(Facter.value(:pip_version)).to eq('6.0.6')
2120
end
2221
end
2322

2423
context 'returns nil when pip not present' do
2524
it do
26-
Facter::Util::Resolution.stubs(:exec)
27-
Facter::Util::Resolution.expects(:which).with('pip').returns(false)
25+
allow(Facter::Util::Resolution).to receive(:which).with('pip').and_return(false)
2826
expect(Facter.value(:pip_version)).to eq(nil)
2927
end
3028
end

spec/unit/facter/python_release_spec.rb

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,16 @@
1919
describe 'python_release' do
2020
context 'returns Python release when `python` present' do
2121
it do
22-
Facter::Util::Resolution.stubs(:exec)
23-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
24-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python2_version_output)
22+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
23+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
2524
expect(Facter.value(:python_release)).to eq('2.7')
2625
end
2726
end
2827

2928
context 'returns nil when `python` not present' do
3029
it do
31-
Facter::Util::Resolution.stubs(:exec)
32-
Facter::Util::Resolution.expects(:which).with('python').returns(false)
30+
allow(Facter::Util::Resolution).to receive(:exec).and_return(false)
31+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
3332
expect(Facter.value(:python_release)).to eq(nil)
3433
end
3534
end
@@ -38,39 +37,35 @@
3837
describe 'python2_release' do
3938
context 'returns Python 2 release when `python` is present and Python 2' do
4039
it do
41-
Facter::Util::Resolution.stubs(:exec)
42-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
43-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python2_version_output)
40+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
41+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
4442
expect(Facter.value(:python2_release)).to eq('2.7')
4543
end
4644
end
4745

4846
context 'returns Python 2 release when `python` is Python 3 and `python2` is present' do
4947
it do
50-
Facter::Util::Resolution.stubs(:exec)
51-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
52-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python3_version_output)
53-
Facter::Util::Resolution.expects(:which).with('python2').returns(true)
54-
Facter::Util::Resolution.expects(:exec).with('python2 -V 2>&1').returns(python2_version_output)
48+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
49+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
50+
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(true)
51+
allow(Facter::Util::Resolution).to receive(:exec).with('python2 -V 2>&1').and_return(python2_version_output)
5552
expect(Facter.value(:python2_release)).to eq('2.7')
5653
end
5754
end
5855

5956
context 'returns nil when `python` is Python 3 and `python2` is absent' do
6057
it do
61-
Facter::Util::Resolution.stubs(:exec)
62-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
63-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python3_version_output)
64-
Facter::Util::Resolution.expects(:which).with('python2').returns(false)
58+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
59+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
60+
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
6561
expect(Facter.value(:python2_release)).to eq(nil)
6662
end
6763
end
6864

6965
context 'returns nil when `python2` and `python` are absent' do
7066
it do
71-
Facter::Util::Resolution.stubs(:exec)
72-
Facter::Util::Resolution.expects(:which).with('python').returns(false)
73-
Facter::Util::Resolution.expects(:which).with('python2').returns(false)
67+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
68+
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
7469
expect(Facter.value(:python2_release)).to eq(nil)
7570
end
7671
end
@@ -79,17 +74,15 @@
7974
describe 'python3_release' do
8075
context 'returns Python 3 release when `python3` present' do
8176
it do
82-
Facter::Util::Resolution.stubs(:exec)
83-
Facter::Util::Resolution.expects(:which).with('python3').returns(true)
84-
Facter::Util::Resolution.expects(:exec).with('python3 -V 2>&1').returns(python3_version_output)
77+
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(true)
78+
allow(Facter::Util::Resolution).to receive(:exec).with('python3 -V 2>&1').and_return(python3_version_output)
8579
expect(Facter.value(:python3_release)).to eq('3.3')
8680
end
8781
end
8882

8983
context 'returns nil when `python3` not present' do
9084
it do
91-
Facter::Util::Resolution.stubs(:exec)
92-
Facter::Util::Resolution.expects(:which).with('python3').returns(false)
85+
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(false)
9386
expect(Facter.value(:python3_release)).to eq(nil)
9487
end
9588
end

spec/unit/facter/python_version_spec.rb

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@
1919
describe 'python_version' do
2020
context 'returns Python version when `python` present' do
2121
it do
22-
Facter::Util::Resolution.stubs(:exec)
23-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
24-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python2_version_output)
22+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
23+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
2524
expect(Facter.value(:python_version)).to eq('2.7.9')
2625
end
2726
end
2827

2928
context 'returns nil when `python` not present' do
3029
it do
31-
Facter::Util::Resolution.stubs(:exec)
32-
Facter::Util::Resolution.expects(:which).with('python').returns(false)
30+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
3331
expect(Facter.value(:python_version)).to eq(nil)
3432
end
3533
end
@@ -38,39 +36,35 @@
3836
describe 'python2_version' do
3937
context 'returns Python 2 version when `python` is present and Python 2' do
4038
it do
41-
Facter::Util::Resolution.stubs(:exec)
42-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
43-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python2_version_output)
39+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
40+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
4441
expect(Facter.value(:python2_version)).to eq('2.7.9')
4542
end
4643
end
4744

4845
context 'returns Python 2 version when `python` is Python 3 and `python2` is present' do
4946
it do
50-
Facter::Util::Resolution.stubs(:exec)
51-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
52-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python3_version_output)
53-
Facter::Util::Resolution.expects(:which).with('python2').returns(true)
54-
Facter::Util::Resolution.expects(:exec).with('python2 -V 2>&1').returns(python2_version_output)
47+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
48+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
49+
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(true)
50+
allow(Facter::Util::Resolution).to receive(:exec).with('python2 -V 2>&1').and_return(python2_version_output)
5551
expect(Facter.value(:python2_version)).to eq('2.7.9')
5652
end
5753
end
5854

5955
context 'returns nil when `python` is Python 3 and `python2` is absent' do
6056
it do
61-
Facter::Util::Resolution.stubs(:exec)
62-
Facter::Util::Resolution.expects(:which).with('python').returns(true)
63-
Facter::Util::Resolution.expects(:exec).with('python -V 2>&1').returns(python3_version_output)
64-
Facter::Util::Resolution.expects(:which).with('python2').returns(false)
57+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
58+
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
59+
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
6560
expect(Facter.value(:python2_version)).to eq(nil)
6661
end
6762
end
6863

6964
context 'returns nil when `python2` and `python` are absent' do
7065
it do
71-
Facter::Util::Resolution.stubs(:exec)
72-
Facter::Util::Resolution.expects(:which).with('python').returns(false)
73-
Facter::Util::Resolution.expects(:which).with('python2').returns(false)
66+
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
67+
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
7468
expect(Facter.value(:python2_version)).to eq(nil)
7569
end
7670
end
@@ -79,17 +73,15 @@
7973
describe 'python3_version' do
8074
context 'returns Python 3 version when `python3` present' do
8175
it do
82-
Facter::Util::Resolution.stubs(:exec)
83-
Facter::Util::Resolution.expects(:which).with('python3').returns(true)
84-
Facter::Util::Resolution.expects(:exec).with('python3 -V 2>&1').returns(python3_version_output)
76+
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(true)
77+
allow(Facter::Util::Resolution).to receive(:exec).with('python3 -V 2>&1').and_return(python3_version_output)
8578
expect(Facter.value(:python3_version)).to eq('3.3.0')
8679
end
8780
end
8881

8982
context 'returns nil when `python3` not present' do
9083
it do
91-
Facter::Util::Resolution.stubs(:exec)
92-
Facter::Util::Resolution.expects(:which).with('python3').returns(false)
84+
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(false)
9385
expect(Facter.value(:python3_version)).to eq(nil)
9486
end
9587
end

spec/unit/facter/virtualenv_version_spec.rb

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
describe 'virtualenv_version old' do
2121
context 'returns virtualenv version when virtualenv present' do
2222
it do
23-
Facter::Util::Resolution.stubs(:exec)
24-
Facter::Util::Resolution.expects(:which).with('virtualenv').returns(true)
25-
Facter::Util::Resolution.expects(:exec).with('virtualenv --version 2>&1').returns(virtualenv_old_version_output)
23+
allow(Facter::Util::Resolution).to receive(:which).with('virtualenv').and_return(true)
24+
allow(Facter::Util::Resolution).to receive(:exec).with('virtualenv --version 2>&1').and_return(virtualenv_old_version_output)
2625
expect(Facter.value(:virtualenv_version)).to eq('12.0.7')
2726
end
2827
end
2928

3029
context 'returns nil when virtualenv not present' do
3130
it do
32-
Facter::Util::Resolution.stubs(:exec)
33-
Facter::Util::Resolution.expects(:which).with('virtualenv').returns(false)
31+
allow(Facter::Util::Resolution).to receive(:which).with('virtualenv').and_return(false)
3432
expect(Facter.value(:virtualenv_version)).to eq(nil)
3533
end
3634
end
@@ -39,19 +37,10 @@
3937
describe 'virtualenv_version new' do
4038
context 'returns virtualenv version when virtualenv present' do
4139
it do
42-
Facter::Util::Resolution.stubs(:exec)
43-
Facter::Util::Resolution.expects(:which).with('virtualenv').returns(true)
44-
Facter::Util::Resolution.expects(:exec).with('virtualenv --version 2>&1').returns(virtualenv_new_version_output)
40+
allow(Facter::Util::Resolution).to receive(:which).with('virtualenv').and_return(true)
41+
allow(Facter::Util::Resolution).to receive(:exec).with('virtualenv --version 2>&1').and_return(virtualenv_new_version_output)
4542
expect(Facter.value(:virtualenv_version)).to eq('20.0.17')
4643
end
4744
end
48-
49-
context 'returns nil when virtualenv not present' do
50-
it do
51-
Facter::Util::Resolution.stubs(:exec)
52-
Facter::Util::Resolution.expects(:which).with('virtualenv').returns(false)
53-
expect(Facter.value(:virtualenv_version)).to eq(nil)
54-
end
55-
end
5645
end
5746
end

0 commit comments

Comments
 (0)