chefspec 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/chefspec.rb CHANGED
@@ -10,7 +10,11 @@ if defined?(RSpec)
10
10
  require 'chefspec/matchers/package'
11
11
  require 'chefspec/matchers/service'
12
12
  require 'chefspec/matchers/shared'
13
+ require 'chefspec/matchers/notifications'
13
14
  require 'chefspec/matchers/file_content'
15
+ require 'chefspec/matchers/user'
16
+ require 'chefspec/matchers/env'
17
+ require 'chefspec/matchers/include_recipe'
14
18
  end
15
19
  require 'chefspec/minitest'
16
20
  require 'chefspec/monkey_patches/hash'
@@ -111,52 +111,15 @@ module ChefSpec
111
111
  self
112
112
  end
113
113
 
114
- # Find any directory declared with the given path
115
- #
116
- # @param [String] path The directory path
117
- # @return [Chef::Resource::Directory] The matching directory, or Nil
118
- def directory(path)
119
- find_resource('directory', path)
120
- end
121
-
122
- # Find any cookbook_file declared with the given path
123
- #
124
- # @param [String] path The cookbook_file path
125
- # @return [Chef::Resource::Directory] The matching cookbook_file, or Nil
126
- def cookbook_file(path)
127
- find_resource('cookbook_file', path)
128
- end
129
-
130
- # Find any file declared with the given path
131
- #
132
- # @param [String] path The file path
133
- # @return [Chef::Resource::Directory] The matching file, or Nil
134
- def file(path)
135
- find_resource('file', path)
136
- end
137
-
138
- # Find any template declared with the given path
139
- #
140
- # @param [String] path The template path
141
- # @return [Chef::Resource::Directory] The matching template, or Nil
142
- def template(path)
143
- find_resource('template', path)
144
- end
145
-
146
- # Find any link declared with the given target_file
147
- #
148
- # @param [String] target_file The link's target_file
149
- # @return [Chef::Resource::Directory] The matching link, or Nil
150
- def link(target_file)
151
- find_resource('link', target_file)
152
- end
153
-
154
- # Find a crontab entry declared with the given name
155
- #
156
- # @param [String] name of a crontab
157
- # @return [Chef::Resource::Cron] The matching cron resource, or Nil
158
- def cron(name)
159
- find_resource('cron', name)
114
+ FILE_RESOURCES = %w(directory cookbook_file file template link remote_directory remote_file)
115
+ PACKAGE_RESOURCES = %w(package apt_package dpkg_package easy_install_package freebsd_package macports_package portage_package rpm_package chef_gem solaris_package yum_package zypper_package)
116
+ SCRIPT_RESOURCES = %w(script powershell bash csh perl python ruby)
117
+ MISC_RESOURCES = %w(cron env user execute service log route ruby_block git subversion group mount ohai ifconfig deploy http_request)
118
+
119
+ (FILE_RESOURCES + PACKAGE_RESOURCES + SCRIPT_RESOURCES + MISC_RESOURCES).sort.uniq.each do |type|
120
+ define_method(type) do |name|
121
+ find_resource(type, name)
122
+ end
160
123
  end
161
124
 
162
125
  # This runner as a string.
@@ -178,8 +141,8 @@ module ChefSpec
178
141
  {:os => 'chefspec', :os_version => ChefSpec::VERSION, :fqdn => 'chefspec.local', :domain => 'local',
179
142
  :ipaddress => '127.0.0.1', :hostname => 'chefspec', :languages => Mash.new({"ruby" => "/usr/somewhere"}),
180
143
  :kernel => Mash.new({:machine => 'i386'})}.each_pair do |attribute,value|
181
- ohai[attribute] = value
182
- end
144
+ ohai[attribute] = value
145
+ end
183
146
  end
184
147
 
185
148
  # Infer the default cookbook path from the location of the calling spec.
@@ -0,0 +1,8 @@
1
+
2
+ require 'chefspec/matchers/shared'
3
+
4
+ module ChefSpec
5
+ module Matchers
6
+ define_resource_matchers([:create, :delete,:modify], [:env], :key_name)
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ require 'chefspec/matchers/shared'
2
+
3
+ module ChefSpec
4
+ module Matchers
5
+ RSpec::Matchers.define :include_recipe do |expected_recipe|
6
+ match do |chef_run|
7
+ actual_recipes = chef_run.node.run_state[:seen_recipes]
8
+ actual_recipes.include?(expected_recipe)
9
+ end
10
+
11
+ failure_message_for_should do |chef_run|
12
+ "expected: ['#{expected_recipe}']\n" +
13
+ " got: #{chef_run.node.run_state.recipes}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ require 'chefspec/matchers/shared'
2
+
3
+ module ChefSpec
4
+ module Matchers
5
+
6
+
7
+ RSpec::Matchers.define :notify do |expected_resource,expected_resource_action|
8
+
9
+ expected_resource.match(/^([^\[]*)\[(.*)\]$/)
10
+ expected_resource_name = $2
11
+ expected_resource_type = $1
12
+ match do |actual_resource|
13
+ notifications = actual_resource.delayed_notifications
14
+ notifications+= actual_resource.immediate_notifications
15
+ notifications.any? do |rs|
16
+
17
+ actual_resource_name = rs.resource.name.to_s
18
+ actual_resource_type = rs.resource.resource_name.to_s
19
+ actual_resource_action = rs.action
20
+
21
+ (actual_resource_name == expected_resource_name) and
22
+ (actual_resource_type == expected_resource_type) and
23
+ (actual_resource_action.to_s == expected_resource_action.to_s)
24
+ end
25
+ end
26
+
27
+ failure_message_for_should do |actual_resource|
28
+ "expected: ['#{expected_resource_action}, #{expected_resource}']\n" +
29
+ " got: #{format_notifications(actual_resource)} "
30
+ end
31
+
32
+ def format_notifications(resource)
33
+ notifications = resource.delayed_notifications
34
+ notifications += resource.immediate_notifications
35
+ msg="["
36
+ notifications.each do |res|
37
+ msg+= "'#{res.action}, #{res.resource.resource_name}[#{res.resource.name}]'"
38
+ end
39
+ msg+="]"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -3,7 +3,10 @@ require 'chefspec/matchers/shared'
3
3
  module ChefSpec
4
4
  module Matchers
5
5
 
6
- define_resource_matchers([:install, :remove, :upgrade, :purge], [:package, :gem_package], :package_name)
6
+ CHEF_GEM_SUPPORTED = defined?(::Chef::Resource::ChefGem)
7
+ PACKAGE_TYPES = [:package, :gem_package, :chef_gem]
8
+ PACKAGE_TYPES << :chef_gem if CHEF_GEM_SUPPORTED
9
+ define_resource_matchers([:install, :remove, :upgrade, :purge], PACKAGE_TYPES, :package_name)
7
10
 
8
11
  RSpec::Matchers.define :install_package_at_version do |package_name, version|
9
12
  match do |chef_run|
@@ -19,5 +22,12 @@ module ChefSpec
19
22
  end
20
23
  end
21
24
  end
25
+ RSpec::Matchers.define :install_chef_gem_at_version do |package_name, version|
26
+ match do |chef_run|
27
+ chef_run.resources.any? do |resource|
28
+ resource_type(resource) == 'chef_gem' and resource.package_name == package_name and resource.action.to_s.include? 'install' and resource.version == version
29
+ end
30
+ end
31
+ end if CHEF_GEM_SUPPORTED
22
32
  end
23
33
  end
@@ -3,7 +3,7 @@ require 'chefspec/matchers/shared'
3
3
  module ChefSpec
4
4
  module Matchers
5
5
 
6
- define_resource_matchers([:start, :stop, :restart, :reload, :nothing, :enable], [:service], :service_name)
6
+ define_resource_matchers([:start, :stop, :restart, :reload, :nothing, :enable, :disable], [:service], :service_name)
7
7
 
8
8
  RSpec::Matchers.define :set_service_to_start_on_boot do |service|
9
9
  match do |chef_run|
@@ -12,5 +12,14 @@ module ChefSpec
12
12
  end
13
13
  end
14
14
  end
15
+
16
+ RSpec::Matchers.define :set_service_to_not_start_on_boot do |service|
17
+ match do |chef_run|
18
+ chef_run.resources.any? do |resource|
19
+ resource_type(resource) == 'service' and resource.service_name == service and resource.action.include? :disable
20
+ end
21
+ end
22
+ end
23
+
15
24
  end
16
25
  end
@@ -51,5 +51,5 @@ end
51
51
  def template_path(template, node)
52
52
  cookbook_name = template.cookbook || template.cookbook_name
53
53
  cookbook = node.cookbook_collection[cookbook_name]
54
- cookbook.preferred_filename_on_disk_location(node, :templates, template.source, template.path)
54
+ cookbook.preferred_filename_on_disk_location(node, :templates, template.source)
55
55
  end
@@ -0,0 +1,8 @@
1
+
2
+ require 'chefspec/matchers/shared'
3
+
4
+ module ChefSpec
5
+ module Matchers
6
+ define_resource_matchers([:create, :remove], [:user], :username)
7
+ end
8
+ end
@@ -122,6 +122,7 @@ module ChefSpec
122
122
  override_assertion :installed, :package_name, [:remove, :purge]
123
123
  override_assertion :enabled, :enabled, [:disable]
124
124
  override_assertion :running, :running, [:stop]
125
+ override_assertion :user_exists, :username, [:remove]
125
126
 
126
127
  def file_resources
127
128
  resources.select{|r| r.resource_name.to_s.end_with?('file')} +
@@ -1,4 +1,4 @@
1
1
  module ChefSpec
2
2
  # The gem version
3
- VERSION = '0.8.0'
3
+ VERSION = '0.9.0'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chefspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-14 00:00:00.000000000 Z
12
+ date: 2012-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -84,14 +84,18 @@ files:
84
84
  - lib/chef/knife/cookbook_create_specs.rb
85
85
  - lib/chefspec/chef_runner.rb
86
86
  - lib/chefspec/matchers/cron.rb
87
+ - lib/chefspec/matchers/env.rb
87
88
  - lib/chefspec/matchers/execute.rb
88
89
  - lib/chefspec/matchers/file.rb
89
90
  - lib/chefspec/matchers/file_content.rb
91
+ - lib/chefspec/matchers/include_recipe.rb
90
92
  - lib/chefspec/matchers/link.rb
91
93
  - lib/chefspec/matchers/log.rb
94
+ - lib/chefspec/matchers/notifications.rb
92
95
  - lib/chefspec/matchers/package.rb
93
96
  - lib/chefspec/matchers/service.rb
94
97
  - lib/chefspec/matchers/shared.rb
98
+ - lib/chefspec/matchers/user.rb
95
99
  - lib/chefspec/minitest.rb
96
100
  - lib/chefspec/monkey_patches/hash.rb
97
101
  - lib/chefspec/monkey_patches/provider.rb
@@ -112,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
116
  version: '0'
113
117
  segments:
114
118
  - 0
115
- hash: -1887236234485155709
119
+ hash: -3567781514066476826
116
120
  required_rubygems_version: !ruby/object:Gem::Requirement
117
121
  none: false
118
122
  requirements:
@@ -121,12 +125,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
125
  version: '0'
122
126
  segments:
123
127
  - 0
124
- hash: -1887236234485155709
128
+ hash: -3567781514066476826
125
129
  requirements: []
126
130
  rubyforge_project:
127
- rubygems_version: 1.8.19
131
+ rubygems_version: 1.8.24
128
132
  signing_key:
129
133
  specification_version: 3
130
- summary: chefspec-0.8.0
134
+ summary: chefspec-0.9.0
131
135
  test_files: []
132
136
  has_rdoc: