Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Commit 1f35f5c

Browse files
committed
Merge pull request voxpupuli#180 from petems/add_facter_spec_tests
Add facter unit tests for version facts
2 parents bc3696b + b9ceeac commit 1f35f5c

5 files changed

Lines changed: 98 additions & 2 deletions

File tree

lib/facter/pip_version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
has_weight 100
1919
setcode do
2020
if Facter::Util::Resolution.which('pip')
21-
Facter::Util::Resolution.exec('pip --version 2>/dev/null').match(/^pip (\d+\.\d+\.?\d*).*$/)[1]
21+
Facter::Util::Resolution.exec('pip --version 2>&1').match(/^pip (\d+\.\d+\.?\d*).*$/)[1]
2222
end
2323
end
2424
end

lib/facter/virtualenv_version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
has_weight 100
1919
setcode do
2020
if Facter::Util::Resolution.which('virtualenv')
21-
Facter::Util::Resolution.exec('virtualenv --version 2>&1')
21+
Facter::Util::Resolution.exec('virtualenv --version 2>&1').match(/^(\d+\.\d+\.?\d*).*$/)[0]
2222
end
2323
end
2424
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
}
7+
8+
let(:pip_version_output) { <<-EOS
9+
pip 6.0.6 from /opt/boxen/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.6-py2.7.egg (python 2.7)
10+
EOS
11+
}
12+
13+
describe "pip_version" do
14+
context 'returns pip version when pip present' do
15+
it do
16+
Facter::Util::Resolution.stubs(:exec)
17+
Facter::Util::Resolution.expects(:which).with("pip").returns(true)
18+
Facter::Util::Resolution.expects(:exec).with("pip --version 2>&1").returns(pip_version_output)
19+
Facter.value(:pip_version).should == "6.0.6"
20+
end
21+
end
22+
23+
context 'returns nil when pip not present' do
24+
it do
25+
Facter::Util::Resolution.stubs(:exec)
26+
Facter::Util::Resolution.expects(:which).with("pip").returns(false)
27+
Facter.value(:pip_version).should == nil
28+
end
29+
end
30+
31+
end
32+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
}
7+
8+
let(:python_version_output) { <<-EOS
9+
Python 2.7.9
10+
EOS
11+
}
12+
13+
describe "python_version" do
14+
context 'returns python version when python present' do
15+
it do
16+
Facter::Util::Resolution.stubs(:exec)
17+
Facter::Util::Resolution.expects(:which).with("python").returns(true)
18+
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python_version_output)
19+
Facter.value(:python_version).should == "2.7.9"
20+
end
21+
end
22+
23+
context 'returns nil when python not present' do
24+
it do
25+
Facter::Util::Resolution.stubs(:exec)
26+
Facter::Util::Resolution.expects(:which).with("python").returns(false)
27+
Facter.value(:python_version).should == nil
28+
end
29+
end
30+
31+
end
32+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
}
7+
8+
let(:virtualenv_version_output) { <<-EOS
9+
12.0.7
10+
EOS
11+
}
12+
13+
describe "virtualenv_version" do
14+
context 'returns virtualenv version when virtualenv present' do
15+
it do
16+
Facter::Util::Resolution.stubs(:exec)
17+
Facter::Util::Resolution.expects(:which).with("virtualenv").returns(true)
18+
Facter::Util::Resolution.expects(:exec).with("virtualenv --version 2>&1").returns(virtualenv_version_output)
19+
Facter.value(:virtualenv_version).should == "12.0.7"
20+
end
21+
end
22+
23+
context 'returns nil when virtualenv not present' do
24+
it do
25+
Facter::Util::Resolution.stubs(:exec)
26+
Facter::Util::Resolution.expects(:which).with("virtualenv").returns(false)
27+
Facter.value(:virtualenv_version).should == nil
28+
end
29+
end
30+
31+
end
32+
end

0 commit comments

Comments
 (0)