|
5 | 5 | Facter.clear |
6 | 6 | } |
7 | 7 |
|
8 | | - let(:python_version_output) { <<-EOS |
| 8 | + let(:python2_version_output) { <<-EOS |
9 | 9 | Python 2.7.9 |
| 10 | +EOS |
| 11 | + } |
| 12 | + let(:python3_version_output) { <<-EOS |
| 13 | +Python 3.3.0 |
10 | 14 | EOS |
11 | 15 | } |
12 | 16 |
|
13 | 17 | describe "python_version" do |
14 | | - context 'returns python version when python present' do |
| 18 | + context 'returns Python version when `python` present' do |
15 | 19 | it do |
16 | 20 | Facter::Util::Resolution.stubs(:exec) |
17 | 21 | Facter::Util::Resolution.expects(:which).with("python").returns(true) |
18 | | - Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python_version_output) |
| 22 | + Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output) |
19 | 23 | Facter.value(:python_version).should == "2.7.9" |
20 | 24 | end |
21 | 25 | end |
22 | 26 |
|
23 | | - context 'returns nil when python not present' do |
| 27 | + context 'returns nil when `python` not present' do |
24 | 28 | it do |
25 | 29 | Facter::Util::Resolution.stubs(:exec) |
26 | 30 | Facter::Util::Resolution.expects(:which).with("python").returns(false) |
|
29 | 33 | end |
30 | 34 |
|
31 | 35 | end |
| 36 | + |
| 37 | + describe "python2_version" do |
| 38 | + context 'returns Python 2 version when `python2` is present' do |
| 39 | + it do |
| 40 | + Facter::Util::Resolution.stubs(:exec) |
| 41 | + Facter::Util::Resolution.expects(:which).with("python2").returns(true) |
| 42 | + Facter::Util::Resolution.expects(:exec).with("python2 -V 2>&1").returns(python2_version_output) |
| 43 | + Facter.value(:python2_version).should == '2.7.9' |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + context 'returns Python 2 version when `python2` is absent and `python` is Python 2' do |
| 48 | + it do |
| 49 | + Facter::Util::Resolution.stubs(:exec) |
| 50 | + Facter::Util::Resolution.expects(:which).with("python2").returns(false) |
| 51 | + Facter::Util::Resolution.expects(:which).with("python").returns(true) |
| 52 | + Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python2_version_output) |
| 53 | + Facter.value(:python2_version).should == '2.7.9' |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + context 'returns nil when `python2` is absent and `python` is Python 3' do |
| 58 | + it do |
| 59 | + Facter::Util::Resolution.stubs(:exec) |
| 60 | + Facter::Util::Resolution.expects(:which).with("python2").returns(false) |
| 61 | + Facter::Util::Resolution.expects(:which).with("python").returns(true) |
| 62 | + Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python3_version_output) |
| 63 | + Facter.value(:python2_version).should == nil |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + context 'returns nil when `python2` and `python` are absent' do |
| 68 | + it do |
| 69 | + Facter::Util::Resolution.stubs(:exec) |
| 70 | + Facter::Util::Resolution.expects(:which).with("python").returns(false) |
| 71 | + Facter::Util::Resolution.expects(:which).with("python2").returns(false) |
| 72 | + Facter.value(:python2_version).should == nil |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + end |
| 77 | + |
| 78 | + describe "python3_version" do |
| 79 | + context 'returns Python 3 version when `python3` present' do |
| 80 | + it do |
| 81 | + Facter::Util::Resolution.stubs(:exec) |
| 82 | + Facter::Util::Resolution.expects(:which).with("python3").returns(true) |
| 83 | + Facter::Util::Resolution.expects(:exec).with("python3 -V 2>&1").returns(python3_version_output) |
| 84 | + Facter.value(:python3_version).should == "3.3.0" |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + context 'returns nil when `python3` not present' do |
| 89 | + it do |
| 90 | + Facter::Util::Resolution.stubs(:exec) |
| 91 | + Facter::Util::Resolution.expects(:which).with("python3").returns(false) |
| 92 | + Facter.value(:python3_version).should == nil |
| 93 | + end |
| 94 | + end |
| 95 | + |
| 96 | + end |
32 | 97 | end |
0 commit comments