Skip to content

Commit

Permalink
Merge pull request voxpupuli#920 from petems/switch_to_rspec_mocks
Browse files Browse the repository at this point in the history
Changes mock from mocha to rspec-mock
  • Loading branch information
bastelfreak authored Oct 12, 2016
2 parents fd58963 + 90c686a commit 5501e88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_facts.yml', __FILE__))
default_facts.merge!(YAML.load(File.read(File.expand_path('../default_module_facts.yml', __FILE__)))) if File.exist?(File.expand_path('../default_module_facts.yml', __FILE__))
c.default_facts = default_facts

c.mock_with :rspec
end

# vim: syntax=ruby
18 changes: 9 additions & 9 deletions spec/unit/facter/util/fact_nginx_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@

context 'neither nginx or openresty in path' do
before do
Facter::Util::Resolution.stubs(:which).with('nginx').returns(false)
Facter::Util::Resolution.stubs(:which).with('openresty').returns(false)
allow(Facter::Util::Resolution).to receive(:which).with('nginx') { false }
allow(Facter::Util::Resolution).to receive(:which).with('openresty') { false }
end
it { expect(Facter.fact(:nginx_version).value).to eq(nil) }
end
context 'nginx' do
context 'with current version output format' do
before do
Facter::Util::Resolution.stubs(:which).with('nginx').returns(true)
Facter::Util::Resolution.stubs(:exec).with('nginx -v 2>&1').returns('nginx version: nginx/1.8.1')
allow(Facter::Util::Resolution).to receive(:which).with('nginx').twice { true }
allow(Facter::Util::Resolution).to receive(:exec).with('nginx -v 2>&1') { 'nginx version: nginx/1.8.1' }
end
it { expect(Facter.fact(:nginx_version).value).to eq('1.8.1') }
end
context 'with old version output format' do
before do
Facter::Util::Resolution.stubs(:which).with('nginx').returns(true)
Facter::Util::Resolution.stubs(:exec).with('nginx -v 2>&1').returns('nginx: nginx version: nginx/0.7.0')
allow(Facter::Util::Resolution).to receive(:which).with('nginx').twice { true }
allow(Facter::Util::Resolution).to receive(:exec).with('nginx -v 2>&1') { 'nginx: nginx version: nginx/0.7.0' }
end
it { expect(Facter.fact(:nginx_version).value).to eq('0.7.0') }
end
end
context 'openresty' do
context 'with current version output format' do
before do
Facter::Util::Resolution.stubs(:which).with('nginx').returns(false)
Facter::Util::Resolution.stubs(:which).with('openresty').returns(true)
Facter::Util::Resolution.stubs(:exec).with('openresty -v 2>&1').returns('nginx version: openresty/1.11.2.1')
allow(Facter::Util::Resolution).to receive(:which).with('nginx').twice { false }
allow(Facter::Util::Resolution).to receive(:which).with('openresty') { true }
allow(Facter::Util::Resolution).to receive(:exec).with('openresty -v 2>&1') { 'nginx version: openresty/1.11.2.1' }
end
it { expect(Facter.fact(:nginx_version).value).to eq('1.11.2.1') }
end
Expand Down

0 comments on commit 5501e88

Please sign in to comment.