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