Skip to content

Commit

Permalink
Complete all pending ChefSpec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Aug 23, 2016
1 parent 62936e8 commit c3ae753
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 274 deletions.
32 changes: 17 additions & 15 deletions libraries/resource_chef_dk_app.rb
Expand Up @@ -36,10 +36,8 @@ class ChefDkApp < Resource
property :version,
[String, FalseClass],
default: 'latest',
callbacks: {
'Invalid version string' =>
->(a) { ::ChefDk::Helpers.valid_version?(a) }
}
callbacks: { 'Invalid version string' =>
->(a) { ::ChefDk::Helpers.valid_version?(a) } }

#
# The Chef-DK can be installed from the :stable or :current channel.
Expand Down Expand Up @@ -101,6 +99,14 @@ class ChefDkApp < Resource
when :repo
install_repo!
else
if new_resource.channel != :stable
raise(Chef::Exceptions::UnsupportedAction,
'A channel property cannot be set with a custom source')
end
if new_resource.version != 'latest'
raise(Chef::Exceptions::UnsupportedAction,
'A version property cannot be set with a custom source')
end
converge_if_changed(:installed) { install_custom! }
end
end
Expand All @@ -116,7 +122,11 @@ class ChefDkApp < Resource
#
action :upgrade do
new_resource.installed(true)
new_resource.version('latest')

if new_resource.version != 'latest'
raise(Chef::Exceptions::UnsupportedAction,
'A version property cannot be used with the :upgrade action')
end

case new_resource.source
when :direct
Expand Down Expand Up @@ -151,16 +161,8 @@ class ChefDkApp < Resource
# must be defined for each sub-provider
#
action_class.class_eval do
%i(
install_direct!
install_repo!
install_custom!
upgrade_direct!
upgrade_repo!
remove_direct!
remove_repo!
remove_custom!
).each do |m|
%i(install_direct! install_repo! install_custom! upgrade_direct!
upgrade_repo! remove_direct! remove_repo! remove_custom!).each do |m|
define_method(m) do
raise(NotImplementedError,
"The `#{m}` method must be implemented for the " \
Expand Down
8 changes: 8 additions & 0 deletions libraries/resource_chef_dk_app_mac_os_x.rb
Expand Up @@ -49,6 +49,14 @@ def install_direct!
# (see Chef::Resource::ChefDkApp#install_repo!
#
def install_repo!
if new_resource.version != 'latest'
raise(Chef::Exceptions::UnsupportedAction,
'A version property cannot be used with the :repo source')
end
if new_resource.channel != :stable
raise(Chef::Exceptions::UnsupportedAction,
'A channel property cannot be used with the :repo source')
end
include_recipe 'homebrew'
homebrew_cask 'chefdk'
end
Expand Down
10 changes: 9 additions & 1 deletion libraries/resource_chef_dk_app_windows.rb
Expand Up @@ -53,9 +53,13 @@ def install_direct!
# (see Chef::Resource::ChefDkApp#install_repo!)
#
def install_repo!
if new_resource.channel != :stable
raise(Chef::Exceptions::UnsupportedAction,
'A channel property cannot be used with the :repo source')
end
include_recipe 'chocolatey'
chocolatey_package 'chefdk' do
if !new_resource.version.nil? && new_resource.version != 'latest'
unless [nil, 'latest'].include?(new_resource.version)
version new_resource.version
end
end
Expand Down Expand Up @@ -93,6 +97,10 @@ def upgrade_direct!
# (see Chef::Resource::ChefDkApp#upgrade_repo!)
#
def upgrade_repo!
if new_resource.channel != :stable
raise(Chef::Exceptions::UnsupportedAction,
'A channel property cannot be used with the :repo source')
end
include_recipe 'chocolatey'
chocolatey_package 'chefdk' do
action :upgrade
Expand Down
52 changes: 52 additions & 0 deletions spec/resources/chef_dk_app.rb
Expand Up @@ -14,6 +14,58 @@

let(:installed_version) { nil }

shared_examples_for 'any platform' do
context 'the default action (:install)' do
context 'a custom source' do
let(:source) { 'https://example.biz.cdk' }

context 'an overridden channel property' do
let(:channel) { :current }

it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end

context 'an overridden version property' do
let(:version) { '4.5.6' }

it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
end
end

context 'the :upgrade action' do
let(:action) { :upgrade }

context 'a custom source' do
let(:source) { 'https://example.biz.cdk' }

it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end

context 'an overridden version property' do
let(:version) { '1.2.3' }

it 'raises an error' do
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
end
end

shared_context 'the default action (:install)' do
before(:each) do
allow(Kernel).to receive(:load).and_call_original
Expand Down
69 changes: 2 additions & 67 deletions spec/resources/chef_dk_app/debian.rb
Expand Up @@ -11,6 +11,8 @@
end

shared_examples_for 'any Debian platform' do
it_behaves_like 'any platform'

context 'the default action (:install)' do
include_context description

Expand Down Expand Up @@ -122,24 +124,6 @@
end
end

context 'an overridden channel property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'an overridden version property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'the latest version already installed' do
include_context description

Expand Down Expand Up @@ -193,15 +177,6 @@
end
end

context 'an overridden version property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'the latest version already installed' do
include_context description

Expand Down Expand Up @@ -244,46 +219,6 @@
it_behaves_like 'any property set'
end
end

context 'an overridden version property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end
end

context 'a custom source' do
include_context description

context 'all default properties' do
include_context description

it 'raises an error' do
expect { chef_run }
.to raise_error(Chef::Exceptions::UnsupportedAction)
end
end

context 'an overridden channel property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'an overridden version property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end
end
end

Expand Down
70 changes: 8 additions & 62 deletions spec/resources/chef_dk_app/mac_os_x.rb
Expand Up @@ -20,6 +20,8 @@
end

shared_examples_for 'any Mac OS X platform' do
it_behaves_like 'any platform'

context 'the default action (:install)' do
include_context description

Expand Down Expand Up @@ -92,17 +94,19 @@
include_context description

it 'raises an error' do
pending
expect(false).to eq(true)
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end

context 'an overridden channel property' do
include_context description

it 'raises an error' do
pending
expect(false).to eq(true)
expect { chef_run }.to raise_error(
Chef::Exceptions::UnsupportedAction
)
end
end
end
Expand Down Expand Up @@ -130,24 +134,6 @@
end
end

context 'an overridden channel property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'an overridden version property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'the latest version already installed' do
include_context description

Expand Down Expand Up @@ -197,15 +183,6 @@
end
end

context 'an overridden version property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'the latest version already installed' do
include_context description

Expand Down Expand Up @@ -253,37 +230,6 @@
end
end
end

context 'a custom source' do
include_context description

context 'all default properties' do
include_context description

it 'raises an error' do
expect { chef_run }
.to raise_error(Chef::Exceptions::UnsupportedAction)
end
end

context 'an overridden channel property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end

context 'an overridden version property' do
include_context description

it 'raises an error' do
pending
expect(true).to eq(false)
end
end
end
end

context 'the :remove action' do
Expand Down

0 comments on commit c3ae753

Please sign in to comment.