-
-
Notifications
You must be signed in to change notification settings - Fork 376
Expand file tree
/
Copy pathpython_version_spec.rb
More file actions
91 lines (80 loc) · 3.3 KB
/
python_version_spec.rb
File metadata and controls
91 lines (80 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true
require 'spec_helper'
describe Facter::Util::Fact do
before do
Facter.clear
end
let(:python2_version_output) do
<<~EOS
Python 2.7.9
EOS
end
let(:python3_version_output) do
<<~EOS
Python 3.3.0
EOS
end
describe 'python_version' do
context 'returns Python version when `python` present' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
expect(Facter.value(:python_version)).to eq('2.7.9')
end
end
context 'returns nil when `python` not present' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
expect(Facter.value(:python_version)).to be_nil
end
end
end
describe 'python2_version' do
context 'returns Python 2 version when `python` is present and Python 2' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python2_version_output)
expect(Facter.value(:python2_version)).to eq('2.7.9')
end
end
context 'returns Python 2 version when `python` is Python 3 and `python2` is present' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('python2 -V 2>&1').and_return(python2_version_output)
expect(Facter.value(:python2_version)).to eq('2.7.9')
end
end
context 'returns nil when `python` is Python 3 and `python2` is absent' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('python -V 2>&1').and_return(python3_version_output)
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
expect(Facter.value(:python2_version)).to be_nil
end
end
context 'returns nil when `python2` and `python` are absent' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python2').and_return(false)
allow(Facter::Util::Resolution).to receive(:which).with('python').and_return(false)
expect(Facter.value(:python2_version)).to be_nil
end
end
end
describe 'python3_version' do
context 'returns Python 3 version when `python3` present' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('python3 -V 2>&1').and_return(python3_version_output)
expect(Facter.value(:python3_version)).to eq('3.3.0')
end
end
context 'returns nil when `python3` not present' do
it do
allow(Facter::Util::Resolution).to receive(:which).with('python3').and_return(false)
expect(Facter.value(:python3_version)).to be_nil
end
end
end
end