Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add support for chef_gem resource #66

Closed
wants to merge 9 commits into from

8 participants

Jim Hopp Augusto Becciu Andrew Crump jimhopp-lookout Steven Wagner Chris Lundquist Ketan Padegaonkar Mathias Lafeldt
Jim Hopp
Collaborator

It would be handy if chefspec supported the 'chef_gem' resource in addition to the 'gem_package' resource.

I'm not sure that some of the actions (:remove, :purge) are strictly necessary for chef_gem but included them to be complete.

Jim Hopp
Collaborator

So I thought chef_gem had been in chef for awhile; turns out it arrived in 0.10.10.

Given that, is it worth adding support for chef_gem? My inclination is yes, but I want to know what the community thinks.

Augusto Becciu

+1

Andrew Crump
Collaborator

Hi Jim,

I agree that this looks very useful - thanks a lot! At the moment this pull request breaks the build on Travis because the current build matrix includes older versions of Chef that don't have the chef_gem resource.

We have a feature tag @requires_chef_10 that clumsily allows exclusion of features that depend on Chef 10+. It's not quite as simple as just adding this tag to your new feature though because as you point out chef_gem will break on versions older than 0.10.10 (including 0.10.8). The easiest thing would be to bump the version of Chef in the build matrix.

This also makes me think we should consider retiring support for Chef 0.9.x from ChefSpec given that it is end of life, which would allow us to remove some code.

Cheers,

Andrew.

Augusto Becciu

I completely agree with retiring support for Chef 0.9.x.

jimhopp-lookout
Steven Wagner

+1 on chef_gem support and on retiring support for chef 0.9.x...

Ranjib Dey and others added some commits
Ranjib Dey Fixing typos 16d2ab9
Ranjib Dey Adding cuckes for resource notification assert where notified resourc…
…e has braces in its name
8758138
Chris Lundquist ChrisLundquist [matchers/service.rb] add :disable action 67bef91
Ketan Padegaonkar ketan Add support for testing that a service is not running on boot c6c1d78
Mathias Lafeldt mlafeldt Fix specs to set attributes using node.set in preparation for Chef 11.0
Fixes the following warning with Chef 10.6.2:

	WARN: Setting attributes without specifying a precedence is deprecated and will be
	removed in Chef 11.0. To set attributes at normal precedence, change code like:
	`node["key"] = "value"` # Not this
	to:
	`node.set["key"] = "value"` # This
85cbb2f
Mathias Lafeldt mlafeldt Document create_remote_file in README
Support for remote_file was added with 23f4b34,
but the feature never made it to the README.
2219ad7
Mathias Lafeldt mlafeldt Make it clear that create_file_with_content matches on partial content
At the moment, you have to try it out or search the commit/change log
to figure out the behavior.
1f73c73
jimhopp-lookout jimhopp-lookout chef_gem support only if chef supports it.
The chef_gem resource was added in chef 0.10.10. We shouldn't add in the chef_gem matcher
unless the chef version supports it.
f4b56cd
Jim Hopp
Collaborator

Well, I think I screwed up the git work and picked up several unrelated commits in this branch. I'm going to see if I can straighten it out.

Jim Hopp
Collaborator

Also, I'd like comments on the mechanisms I used to ensure the new functionality only runs if it's on a chef version that supports chef_gem.

Jim Hopp
Collaborator

I'm going to close this pull request since I screwed up the commit history. I've submitted a second pull request (74) with a re-based commit.

Jim Hopp jimhopp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2012
  1. jimhopp-lookout
Commits on Nov 9, 2012
  1. jimhopp-lookout

    Fixing typos

    Ranjib Dey authored jimhopp-lookout committed
  2. jimhopp-lookout

    Adding cuckes for resource notification assert where notified resourc…

    Ranjib Dey authored jimhopp-lookout committed
    …e has braces in its name
  3. Chris Lundquist jimhopp-lookout
  4. Ketan Padegaonkar jimhopp-lookout
  5. Mathias Lafeldt jimhopp-lookout

    Fix specs to set attributes using node.set in preparation for Chef 11.0

    mlafeldt authored jimhopp-lookout committed
    Fixes the following warning with Chef 10.6.2:
    
    	WARN: Setting attributes without specifying a precedence is deprecated and will be
    	removed in Chef 11.0. To set attributes at normal precedence, change code like:
    	`node["key"] = "value"` # Not this
    	to:
    	`node.set["key"] = "value"` # This
  6. Mathias Lafeldt jimhopp-lookout

    Document create_remote_file in README

    mlafeldt authored jimhopp-lookout committed
    Support for remote_file was added with 23f4b34,
    but the feature never made it to the README.
  7. Mathias Lafeldt jimhopp-lookout

    Make it clear that create_file_with_content matches on partial content

    mlafeldt authored jimhopp-lookout committed
    At the moment, you have to try it out or search the commit/change log
    to figure out the behavior.
  8. jimhopp-lookout

    chef_gem support only if chef supports it.

    jimhopp-lookout authored
    The chef_gem resource was added in chef 0.10.10. We shouldn't add in the chef_gem matcher
    unless the chef version supports it.
This page is out of date. Refresh to see the latest.
12 README.md
View
@@ -295,12 +295,18 @@ Assert that a file would have the correct ownership:
chef_run.file('/var/log/bar.log').should be_owned_by('user', 'group')
```
-Assert that a file would have the expected content:
+Assert that a file would have the expected content (matches on partial content):
```ruby
chef_run.should create_file_with_content 'hello-world.txt', 'hello world'
```
+Assert that a remote file would be created:
+
+```ruby
+chef_run.should create_remote_file '/tmp/foo.tar.gz'
+```
+
## Packages
Note that only packages explicitly declared in the cookbook will be matched by
@@ -343,6 +349,10 @@ All of the assertions above are also valid for use with RubyGems:
chef_run.should install_gem_package 'foo'
```
+```ruby
+chef_run.should install_chef_gem_package 'chef-foo'
+```
+
## Execute
If you make use of the `execute` resource within your cookbook recipes it is
1  Rakefile
View
@@ -19,6 +19,7 @@ def register_spec_features(spec_type)
"Run Cucumber features (#{spec_type} support only)") do |t|
t.cucumber_opts = "CS_SPEC_TYPE=#{spec_type} features --format pretty"
t.cucumber_opts << ' -t ~@requires_chef_10' if Chef::VERSION.start_with? '0.9.'
+ t.cucumber_opts << ' -t ~@chefgem' unless defined?(Chef::Resource::ChefGem)
t.cucumber_opts << " -t ~@not_implemented_#{spec_type.downcase}"
end
end
63 features/step_definitions/chef_gem_package_steps.rb
View
@@ -0,0 +1,63 @@
+Given 'a Chef cookbook with a recipe that declares a chef gem package resource' do
+ recipe_installs_chef_gem
+end
+
+Given 'a Chef cookbook with a recipe that declares a chef gem package resource with no action specified' do
+ recipe_with_chef_gem_no_action
+end
+
+Given 'a Chef cookbook with a recipe that declares a chef gem package resource at a fixed version' do
+ recipe_installs_specific_chef_gem_version
+end
+
+Given 'a Chef cookbook with a recipe that declares a chef gem package resource at a fixed version with no action specified' do
+ recipe_installs_specific_chef_gem_version_with_no_action
+end
+
+Given 'a Chef cookbook with a recipe that upgrades a chef gem package' do
+ recipe_upgrades_chef_gem
+end
+
+Given 'a Chef cookbook with a recipe that removes a chef gem package' do
+ recipe_removes_chef_gem
+end
+
+Given 'a Chef cookbook with a recipe that purges a chef gem package' do
+ recipe_purges_chef_gem
+end
+
+Given 'the recipe has a spec example that expects the chef gem package to be installed' do
+ spec_expects_chef_gem_action(:install)
+end
+
+Given 'the recipe has a spec example that expects the chef gem package to be upgraded' do
+ spec_expects_chef_gem_action(:upgrade)
+end
+
+Given 'the recipe has a spec example that expects the chef gem package to be removed' do
+ spec_expects_chef_gem_action(:remove)
+end
+
+Given 'the recipe has a spec example that expects the chef gem package to be purged' do
+ spec_expects_chef_gem_action(:purge)
+end
+
+Given 'the recipe has a spec example that expects the chef gem package to be installed at that version' do
+ spec_expects_chef_gem_at_specific_version
+end
+
+Then 'the chef gem package will not have been installed' do
+ # chef gem package installation would fail
+end
+
+Then 'the chef gem package will not have been upgraded' do
+ # chef gem package upgrade would fail
+end
+
+Then 'the chef gem package will not have been removed' do
+ # chef gem package removal would fail
+end
+
+Then 'the chef gem package will not have been purged' do
+ # chef gem package purge would fail
+end
6 features/step_definitions/notification_steps.rb
View
@@ -9,3 +9,9 @@
Then /the notify assertion will be succesfully evaluated/ do
end
+Given /^a Chef cookbook with a recipe in which a template notifies a service having braces in its name$/ do
+ recipe_with_template_notifying_service_having_braces_in_name
+end
+Given /^the recipe has a spec example that assert on the notification service having braces in its name$/ do
+ spec_expects_template_notifies_service_having_braces_in_its_name
+end
67 features/support/example_helpers.rb
View
@@ -104,6 +104,14 @@ def recipe_installs_gem
}
end
+ def recipe_installs_chef_gem
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ chef_gem "chef_gem_does_not_exist" do
+ action :install
+ end
+ }
+ end
+
def recipe_installs_package
write_file 'cookbooks/example/recipes/default.rb', %q{
package "package_does_not_exist" do
@@ -127,6 +135,15 @@ def recipe_installs_specific_gem_version
}
end
+ def recipe_installs_specific_chef_gem_version
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ chef_gem "chef_gem_does_not_exist" do
+ version "1.2.3"
+ action :install
+ end
+ }
+ end
+
def recipe_installs_specific_package_version
write_file "cookbooks/example/recipes/default.rb", %q{
package "package_does_not_exist" do
@@ -144,6 +161,14 @@ def recipe_installs_specific_gem_version_with_no_action
}
end
+ def recipe_installs_specific_chef_gem_version_with_no_action
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ chef_gem "chef_gem_does_not_exist" do
+ version "1.2.3"
+ end
+ }
+ end
+
def recipe_installs_specific_package_version_with_no_action
write_file 'cookbooks/example/recipes/default.rb', %q{
package "package_does_not_exist" do
@@ -166,6 +191,14 @@ def recipe_purges_gem
}
end
+ def recipe_purges_chef_gem
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ chef_gem "chef_gem_does_not_exist" do
+ action :purge
+ end
+ }
+ end
+
def recipe_purges_package
write_file "cookbooks/example/recipes/default.rb", %q{
package "package_does_not_exist" do
@@ -199,6 +232,14 @@ def recipe_removes_gem
}
end
+ def recipe_removes_chef_gem
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ chef_gem "chef_gem_does_not_exist" do
+ action :remove
+ end
+ }
+ end
+
def recipe_removes_package
write_file "cookbooks/example/recipes/default.rb", %q{
package "package_does_not_exist" do
@@ -304,6 +345,14 @@ def recipe_upgrades_gem
}
end
+ def recipe_upgrades_chef_gem
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ chef_gem "chef_gem_does_not_exist" do
+ action :upgrade
+ end
+ }
+ end
+
def recipe_with_cookbook_file
write_file 'cookbooks/example/files/default/hello-world.txt', 'hello world!'
write_file 'cookbooks/example/recipes/default.rb', 'cookbook_file "hello-world.txt"'
@@ -324,6 +373,12 @@ def recipe_with_gem_no_action
}
end
+ def recipe_with_chef_gem_no_action
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ chef_gem "chef_gem_does_not_exist"
+ }
+ end
+
def recipe_with_remote_file
write_file 'cookbooks/example/recipes/default.rb', %q{
remote_file "hello-world.txt" do
@@ -358,6 +413,18 @@ def recipe_with_template_notifying_service
end
}
end
+
+ def recipe_with_template_notifying_service_having_braces_in_name
+ write_file 'cookbooks/example/recipes/default.rb', %q{
+ template "/etc/foo" do
+ notifies :restart ,"service[bar[v1.1]]"
+ end
+ service "bar[v1.1]" do
+ action :start
+ end
+ }
+ end
+
def recipe_includes_another_recipe
write_file 'cookbooks/example/recipes/default.rb', %q{
include_recipe 'example::foo'
20 features/support/minitest_helpers.rb
View
@@ -101,6 +101,26 @@ def spec_expects_gem_at_specific_version
}
end
+ def spec_expects_chef_gem_action(action)
+ assertion = case action
+ when :remove, :purge then 'wont_be_installed'
+ else 'must_be_installed'
+ end
+ generate_spec %Q{
+ it "#{action}s the chef gem" do
+ chef_gem("chef_gem_does_not_exist").#{assertion}
+ end
+ }
+ end
+
+ def spec_expects_chef_gem_at_specific_version
+ generate_spec %q{
+ it "installs the chef gem at a specific version" do
+ chef_gem("chef_gem_does_not_exist").must_be_installed.with(:version, '1.2.3')
+ end
+ }
+ end
+
def spec_expects_package_action(action)
assertion = case action
when :remove, :purge then 'wont_be_installed'
39 features/support/rspec_helpers.rb
View
@@ -205,6 +205,32 @@ def spec_expects_gem_at_specific_version
}
end
+ def spec_expects_chef_gem_action(action)
+ write_file 'cookbooks/example/spec/default_spec.rb', %Q{
+ require "chefspec"
+
+ describe "example::default" do
+ let(:chef_run) { ChefSpec::ChefRunner.new.converge 'example::default' }
+ it "should #{action.to_s} package_does_not_exist" do
+ chef_run.should #{action.to_s}_chef_gem 'chef_gem_does_not_exist'
+ end
+ end
+ }
+ end
+
+ def spec_expects_chef_gem_at_specific_version
+ write_file 'cookbooks/example/spec/default_spec.rb', %q{
+ require "chefspec"
+
+ describe "example::default" do
+ let(:chef_run) {ChefSpec::ChefRunner.new.converge 'example::default'}
+ it "should install chef_gem_does_not_exist at a specific version" do
+ chef_run.should install_chef_gem_at_version 'chef_gem_does_not_exist', '1.2.3'
+ end
+ end
+ }
+ end
+
def spec_expects_package_action(action)
write_file 'cookbooks/example/spec/default_spec.rb', %Q{
require "chefspec"
@@ -366,6 +392,19 @@ def spec_expects_template_notifies_service
}
end
+ def spec_expects_template_notifies_service_having_braces_in_its_name
+ write_file 'cookbooks/example/spec/default_spec.rb', %Q{
+ require "chefspec"
+
+ describe "example::default" do
+ let(:chef_run) { ChefSpec::ChefRunner.new.converge 'example::default' }
+ it "template 'foo' should notify resource 'bar'" do
+ chef_run.template('/etc/foo').should notify('service[bar[v1.1]]',:restart)
+ end
+ end
+ }
+ end
+
def spec_expects_include_recipe
write_file 'cookbooks/example/spec/default_spec.rb', %Q{
require "chefspec"
48 features/write_examples_for_chef_gem_packages.feature
View
@@ -0,0 +1,48 @@
+@chefgem
+Feature: Write examples for chef gem packages
+
+ Express an expectation that a chef gem package will be installed:
+
+ chef_run.should install_chef gem_package 'foo'
+
+ Scenario: chef gem package resource
+ Given a Chef cookbook with a recipe that declares a chef gem package resource
+ And the recipe has a spec example that expects the chef gem package to be installed
+ When the recipe example is successfully run
+ Then the chef gem package will not have been installed
+
+ Scenario: Package resource with default action
+ Given a Chef cookbook with a recipe that declares a chef gem package resource with no action specified
+ And the recipe has a spec example that expects the chef gem package to be installed
+ When the recipe example is successfully run
+ Then the chef gem package will not have been installed
+
+ Scenario: Package resource with fixed version
+ Given a Chef cookbook with a recipe that declares a chef gem package resource at a fixed version
+ And the recipe has a spec example that expects the chef gem package to be installed at that version
+ When the recipe example is successfully run
+ Then the chef gem package will not have been installed
+
+ Scenario: Package resource with fixed version and default action
+ Given a Chef cookbook with a recipe that declares a chef gem package resource at a fixed version with no action specified
+ And the recipe has a spec example that expects the chef gem package to be installed at that version
+ When the recipe example is successfully run
+ Then the chef gem package will not have been installed
+
+ Scenario: Upgrade a package
+ Given a Chef cookbook with a recipe that upgrades a chef gem package
+ And the recipe has a spec example that expects the chef gem package to be upgraded
+ When the recipe example is successfully run
+ Then the chef gem package will not have been upgraded
+
+ Scenario: Remove a package
+ Given a Chef cookbook with a recipe that removes a chef gem package
+ And the recipe has a spec example that expects the chef gem package to be removed
+ When the recipe example is successfully run
+ Then the chef gem package will not have been removed
+
+ Scenario: Purge a package
+ Given a Chef cookbook with a recipe that purges a chef gem package
+ And the recipe has a spec example that expects the chef gem package to be purged
+ When the recipe example is successfully run
+ Then the chef gem package will not have been purged
6 features/write_examples_for_notification.feature
View
@@ -13,3 +13,9 @@ Feature: Write examples for notifcations
And the recipe has a spec example that assert on the notification
When the recipe example is successfully run
Then the notify assertion will be succesfully evaluated
+
+ Scenario: Notify a resource having square braces in its name
+ Given a Chef cookbook with a recipe in which a template notifies a service having braces in its name
+ And the recipe has a spec example that assert on the notification service having braces in its name
+ When the recipe example is successfully run
+ Then the notify assertion will be succesfully evaluated
12 lib/chefspec/matchers/package.rb
View
@@ -3,7 +3,10 @@
module ChefSpec
module Matchers
- define_resource_matchers([:install, :remove, :upgrade, :purge], [:package, :gem_package], :package_name)
+ CHEF_GEM_SUPPORTED = defined?(::Chef::Resource::ChefGem)
+ PACKAGE_TYPES = [:package, :gem_package, :chef_gem]
+ PACKAGE_TYPES << :chef_gem if CHEF_GEM_SUPPORTED
+ define_resource_matchers([:install, :remove, :upgrade, :purge], PACKAGE_TYPES, :package_name)
RSpec::Matchers.define :install_package_at_version do |package_name, version|
match do |chef_run|
@@ -19,5 +22,12 @@ module Matchers
end
end
end
+ RSpec::Matchers.define :install_chef_gem_at_version do |package_name, version|
+ match do |chef_run|
+ chef_run.resources.any? do |resource|
+ resource_type(resource) == 'chef_gem' and resource.package_name == package_name and resource.action.to_s.include? 'install' and resource.version == version
+ end
+ end
+ end if CHEF_GEM_SUPPORTED
end
end
11 lib/chefspec/matchers/service.rb
View
@@ -3,7 +3,7 @@
module ChefSpec
module Matchers
- define_resource_matchers([:start, :stop, :restart, :reload, :nothing, :enable], [:service], :service_name)
+ define_resource_matchers([:start, :stop, :restart, :reload, :nothing, :enable, :disable], [:service], :service_name)
RSpec::Matchers.define :set_service_to_start_on_boot do |service|
match do |chef_run|
@@ -12,5 +12,14 @@ module Matchers
end
end
end
+
+ RSpec::Matchers.define :set_service_to_not_start_on_boot do |service|
+ match do |chef_run|
+ chef_run.resources.any? do |resource|
+ resource_type(resource) == 'service' and resource.service_name == service and resource.action.include? :disable
+ end
+ end
+ end
+
end
end
19 spec/chefspec/chef_runner_spec.rb
View
@@ -25,6 +25,7 @@ module ChefSpec
Chef::Log.level.should eql :warn
end
it "should set the log_level to any provided value" do
+ Chef::Log.stub(:info)
ChefSpec::ChefRunner.new(:log_level => :info)
Chef::Log.level.should eql :info
end
@@ -59,7 +60,7 @@ module ChefSpec
file.run_action(:create)
end
it "should accept a block to set node attributes" do
- runner = ChefSpec::ChefRunner.new() {|node| node[:foo] = 'baz'}
+ runner = ChefSpec::ChefRunner.new() {|node| node.set[:foo] = 'baz'}
runner.node.foo.should == 'baz'
end
context "default ohai attributes" do
@@ -86,7 +87,7 @@ module ChefSpec
describe "#node" do
it "should allow attributes to be set on the node" do
runner = ChefSpec::ChefRunner.new
- runner.node.foo = 'bar'
+ runner.node.set[:foo] = 'bar'
runner.node.foo.should eq 'bar'
end
end
@@ -103,12 +104,12 @@ module ChefSpec
end
end
describe "#template" do
- it "should not return a resource when the file has not been declared" do
+ it "should not return a resource when the template has not been declared" do
runner = ChefSpec::ChefRunner.new
runner.resources = []
runner.template('/tmp/foo.txt').should_not be
end
- it "should return a resource when the file has been declared" do
+ it "should return a resource when the template has been declared" do
runner = ChefSpec::ChefRunner.new
runner.resources = [{:resource_name => 'template', :name => '/tmp/foo.txt'}]
runner.template('/tmp/foo.txt').should be
@@ -300,7 +301,7 @@ module ChefSpec
runner.resources = []
runner.mount('foo').should_not be
end
- it "should return a resource when the group resource has been declared" do
+ it "should return a resource when the mount resource has been declared" do
runner = ChefSpec::ChefRunner.new
runner.resources = [{:resource_name => 'mount', :name => 'foo'}]
runner.mount('foo').should be
@@ -343,12 +344,12 @@ module ChefSpec
end
end
describe "#http_request" do
- it "should not return a resource when no http request resource has not been declared" do
+ it "should not return a resource when no http_request resource has not been declared" do
runner = ChefSpec::ChefRunner.new
runner.resources = []
runner.http_request('foo').should_not be
end
- it "should return a resource when the deploy resource has been declared" do
+ it "should return a resource when the http_request resource has been declared" do
runner = ChefSpec::ChefRunner.new
runner.resources = [{:resource_name => 'http_request', :name => 'foo'}]
runner.http_request('foo').should be
@@ -372,7 +373,7 @@ module ChefSpec
runner.resources = []
runner.powershell('foo').should_not be
end
- it "should return a resource when the script resource has been declared" do
+ it "should return a resource when the powershell resource has been declared" do
runner = ChefSpec::ChefRunner.new
runner.resources = [{:resource_name => 'powershell', :name => 'foo'}]
runner.powershell('foo').should be
@@ -411,7 +412,7 @@ module ChefSpec
chef_run.to_s.should == 'chef_run'
end
it "should not include node attributes" do
- chef_run.node.foo = 'bar'
+ chef_run.node.set[:foo] = 'bar'
chef_run.node.automatic_attrs[:platform] = 'solaris'
chef_run.converge('apache2::default').to_s.should == 'chef_run: recipe[apache2::default]'
end
27 spec/chefspec/matchers/chef_gem_package_spec.rb
View
@@ -0,0 +1,27 @@
+require 'spec_helper'
+
+module ChefSpec
+ module Matchers
+ describe :install_chef_gem_at_version, :if => defined?(::Chef::Resource::ChefGem) do
+ describe "#match" do
+ let(:matcher) { install_chef_gem_at_version('foo', '1.2.3') }
+ it "should not match when no resources exist" do
+ matcher.matches?({:resources => []}).should be false
+ end
+ it "should not match when there are no chef gem packages" do
+ matcher.matches?({:resources => [{:resource_name => 'template', :path => '/tmp/config.conf',
+ :source => 'config.conf.erb'}]}).should be false
+ end
+ it "should not match if is a different chef gem package and an unspecified version" do
+ matcher.matches?({:resources => [{:resource_name => 'chef_gem', :package_name => 'bar', :version => nil, :action => :install}]}).should be false
+ end
+ it "should not match if it is the same chef gem package and version but a different action" do
+ matcher.matches?({:resources => [{:resource_name => 'chef_gem', :package_name => 'foo', :version => '1.2.3', :action => :upgrade}]}).should be false
+ end
+ it "should match if is the same chef gem package, the correct version and the install action" do
+ matcher.matches?({:resources => [{:resource_name => 'chef_gem', :package_name => 'foo', :version => '1.2.3', :action => :install}]}).should be true
+ end
+ end
+ end
+ end
+end
24 spec/chefspec/matchers/service_spec.rb
View
@@ -24,6 +24,28 @@ module Matchers
matcher.matches?({:resources => [{:resource_name => 'service', :service_name => 'food', :action => [:stop, :enable, :start, :restart]}]}).should be true
end
end
+
+ describe "#set_service_to_not_start_on_boot" do
+ let(:matcher) { matcher = set_service_to_not_start_on_boot('food') }
+ it "should not match when no resources exist" do
+ matcher.matches?({:resources => []}).should be false
+ end
+ it "should not match if no service resource is declared" do
+ matcher.matches?({:resources => [{:resource_name => 'log', :name => 'Installing service...'}]}).should be false
+ end
+ it "should not match if a different service is declared" do
+ matcher.matches?({:resources => [{:resource_name => 'service', :service_name => 'sendmail', :action => [:stop, :disable]}]}).should be false
+ end
+ it "should not match if the service is set to start but not enabled" do
+ matcher.matches?({:resources => [{:resource_name => 'service', :service_name => 'food', :action => [:start]}]}).should be false
+ end
+ it "should match if the service is disabled" do
+ matcher.matches?({:resources => [{:resource_name => 'service', :service_name => 'food', :action => [:disable]}]}).should be true
+ end
+ it "should match if the service is disabled amongst other actions" do
+ matcher.matches?({:resources => [{:resource_name => 'service', :service_name => 'food', :action => [:stop, :disable, :start, :restart]}]}).should be true
+ end
+ end
end
end
-end
+end
Something went wrong with that request. Please try again.