Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Update tests for Chef 14.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderanger committed Apr 18, 2018
1 parent c5db46d commit 99f6abc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
6 changes: 3 additions & 3 deletions test/spec/scl/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def action_run
end # /describe #scl_package

describe '#scl_folder' do
let(:test_provider) { provider(:poise_test).new(nil, nil) }
let(:test_provider) { provider(:poise_test).new(resource(:poise_test).new('test'), nil) }
subject { test_provider.send(:scl_folder) }
before do
allow(test_provider).to receive(:scl_package).and_return({name: 'python34'})
Expand All @@ -96,7 +96,7 @@ def action_run
end # /describe #scl_folder

describe '#scl_environment' do
let(:test_provider) { provider(:poise_test).new(nil, nil) }
let(:test_provider) { provider(:poise_test).new(resource(:poise_test).new('test'), nil) }
subject { test_provider.send(:scl_environment) }
before do
allow(test_provider).to receive(:scl_package).and_return({name: 'python34'})
Expand All @@ -114,7 +114,7 @@ def action_run
allow(File).to receive(:exist?).with('/test/enable').and_return(true)
allow(IO).to receive(:readlines).with('/test/enable').and_return(content.split(/\n/))
end
subject { provider(:poise_test).new(nil, nil).send(:parse_enable_file, '/test/enable') }
subject { provider(:poise_test).new(resource(:poise_test).new('test'), nil).send(:parse_enable_file, '/test/enable') }

context 'with an empty file' do
it { is_expected.to eq({}) }
Expand Down
6 changes: 3 additions & 3 deletions test/spec/system/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ def action_run
end # /describe #uninstall_system_packages

describe '#system_package_candidates' do
subject { provider(:poise_test).new(nil, nil).send(:system_package_candidates, '') }
subject { provider(:poise_test).new(resource(:poise_test).new('test'), nil).send(:system_package_candidates, '') }
it { expect { subject }.to raise_error NotImplementedError }
end # /describe #system_package_candidates

describe '#system_package_name' do
let(:chefspec_options) { {platform: 'debian', version: '7.11'} }
let(:version) { '' }
let(:test_provider) { provider(:poise_test).new(nil, chef_run.run_context) }
let(:test_provider) { provider(:poise_test).new(resource(:poise_test).new('test'), chef_run.run_context) }
provider(:poise_test) do
include described_class
packages('python', {
Expand Down Expand Up @@ -184,7 +184,7 @@ def system_package_candidates(version)
end # /describe #system_package_name

describe '#system_dev_package_overrides' do
subject { provider(:poise_test).new(nil, nil).send(:system_dev_package_overrides) }
subject { provider(:poise_test).new(resource(:poise_test).new('test'), nil).send(:system_dev_package_overrides) }
it { is_expected.to eq({}) }
end # /describe #system_dev_package_overrides

Expand Down
27 changes: 19 additions & 8 deletions test/spec/system/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,25 @@
context 'on CentOS' do
let(:chefspec_options) { {platform: 'centos', version: '7.3.1611'} }
before do
yum_cache = double('YumCache')
allow(yum_cache).to receive(:yum_binary=)
allow(yum_cache).to receive(:disable_extra_repo_control)
allow(yum_cache).to receive(:package_available?).and_return(false)
allow(yum_cache).to receive(:package_available?).with(/^mylang(-devel)?$/).and_return(true)
allow(yum_cache).to receive(:installed_version).with(/^mylang(-devel)?$/, nil).and_return(nil)
allow(yum_cache).to receive(:candidate_version).with(/^mylang(-devel)?$/, nil).and_return('1.2.3')
allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache)
if defined?(Chef::Provider::Package::Yum::PythonHelper.instance)
# New-fangled PythonHelper (Chef 14+).
python_helper = double('PythonHelper')
allow(Chef::Provider::Package::Yum::PythonHelper).to receive(:instance).and_return(python_helper)
allow(python_helper).to receive(:package_query).with(:whatinstalled, 'mylang', version: nil, arch: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang', nil, nil))
allow(python_helper).to receive(:package_query).with(:whatinstalled, 'mylang-devel', version: nil, arch: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang-devel', nil, nil))
allow(python_helper).to receive(:package_query).with(:whatavailable, 'mylang', version: nil, arch: nil, options: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang', '0:1.2.3.el7', 'i386'))
allow(python_helper).to receive(:package_query).with(:whatavailable, 'mylang-devel', version: nil, arch: nil, options: nil).and_return(Chef::Provider::Package::Yum::Version.new('mylang-devel', '0:1.2.3.el7', 'i386'))
else
# Old-school yum cache.
yum_cache = double('YumCache')
allow(yum_cache).to receive(:yum_binary=)
allow(yum_cache).to receive(:disable_extra_repo_control)
allow(yum_cache).to receive(:package_available?).and_return(false)
allow(yum_cache).to receive(:package_available?).with(/^mylang(-devel)?$/).and_return(true)
allow(yum_cache).to receive(:installed_version).with(/^mylang(-devel)?$/, nil).and_return(nil)
allow(yum_cache).to receive(:candidate_version).with(/^mylang(-devel)?$/, nil).and_return('1.2.3')
allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache)
end
end

context 'action :install' do
Expand Down

0 comments on commit 99f6abc

Please sign in to comment.