chefspec 3.3.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83803766a872ecfb05eeea5ecf9f715ca7cfa0e1
4
- data.tar.gz: 43ff5901db1916b48a225a6f5576502c12892002
3
+ metadata.gz: db7a5ff46f8abc2437123170af409eee038f23bb
4
+ data.tar.gz: 37af4d6d9df0ec11b63c73c2ee4d5bb7735c0406
5
5
  SHA512:
6
- metadata.gz: 0020a9532258bf130a8c7b1de8372f09f7b07d03b39f697372b0172b4ed596bee0bce3dfdef169e85fedd413d5f7199727bc6109e8f22c0de34ef4d037f7d1d1
7
- data.tar.gz: 3ddb0c339391d19642ce896041fc2e9fa39545f6c2c4413f3bd530d93b16f81b878a604319321b642f4de89264811317eb62dda35f9bf5ea84e1900c3011ff94
6
+ metadata.gz: 9e9f02d613fe796154fcec30b55d6f716ccb9851aca20a6dc9c632247280658fa88ad9adc13ce56417be0f7c67dd833fb3292260244b664c0156ce7ab36d7f2a
7
+ data.tar.gz: 785722986b2db643a6b4023b8c5d77562d1e91ca1d54df5e453f83bcb1dbc93d6776d4d5b7149652cc00fe10ac12ae7b7a4f55498caeb16ab922dc013041a401
@@ -2,9 +2,11 @@ rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
4
  - 2.1.0
5
+
5
6
  branches:
6
7
  only:
7
8
  - master
9
+
8
10
  notifications:
9
11
  irc:
10
12
  channels:
@@ -13,6 +15,9 @@ notifications:
13
15
  skip_join: true
14
16
  template:
15
17
  - "%{message} (%{author}): %{build_url}"
18
+
19
+ bundler_args: --jobs 7
20
+
16
21
  gemfile:
17
22
  - gemfiles/chef-11.0.0.gemfile
18
23
  - gemfiles/chef-11.2.0.gemfile
@@ -20,6 +25,7 @@ gemfile:
20
25
  - gemfiles/chef-11.6.0.gemfile
21
26
  - gemfiles/chef-11.8.0.gemfile
22
27
  - gemfiles/chef-master.gemfile
28
+
23
29
  matrix:
24
30
  fast_finish: true
25
31
  allow_failures:
@@ -1,6 +1,18 @@
1
1
  CHANGELOG for ChefSpec
2
2
  ======================
3
3
 
4
+ ## 3.3.2 (March 16, 2014)
5
+ Bugfixes:
6
+ - Restore Berkshelf 2 support (missing edge case)
7
+ - Add negative failure message for subscribes/notifies matchers
8
+
9
+ Features:
10
+ - Added `do_nothing` matcher for asserting a resource performed no actions
11
+
12
+ Improvements:
13
+ - Increased spec coverage for matchers
14
+ - Support RSpec matchers in `with_content`
15
+
4
16
  ## 3.3.1 (March 11, 2014)
5
17
  Bugfixes:
6
18
  - Various typographical fixes in the README
data/README.md CHANGED
@@ -267,7 +267,13 @@ expect(chef_run).to render_file('/etc/foo').with_content('This is content')
267
267
  expect(chef_run).to render_file('/etc/foo').with_content(/regex works too.+/)
268
268
  ```
269
269
 
270
- Additionally, it is possible to assert which [Chef phase of execution](http://docs.opscode.com/essentials_nodes_chef_run.html) a resource is created. Given a resource that is installed at compile time using `run_action`:
270
+ You can use any RSpec content matcher inside of the `with_content` predicate:
271
+
272
+ ```ruby
273
+ expect(chef_run).to render_file('/etc/foo').with_content(start_with('# First line'))
274
+ ```
275
+
276
+ It is possible to assert which [Chef phase of execution](http://docs.opscode.com/essentials_nodes_chef_run.html) a resource is created. Given a resource that is installed at compile time using `run_action`:
271
277
 
272
278
  ```ruby
273
279
  package('apache2').run_action(:install)
@@ -287,6 +293,14 @@ expect(chef_run).to install_package('apache2').at_converge_time
287
293
 
288
294
  Since "converge time" is the default behavior for all recipes, this test might be redundant and the predicate could be dropped depending on your situation.
289
295
 
296
+ ##### do_nothing
297
+ Assert that a resource performs no action
298
+
299
+ ```ruby
300
+ resource = chef_run.execute('install')
301
+ expect(resource).to do_nothing
302
+ ```
303
+
290
304
  **For more complex examples, please see the [examples directory](https://github.com/sethvargo/chefspec/tree/master/examples) or the [Yard documentation](http://rubydoc.info/github/sethvargo/chefspec).**
291
305
 
292
306
 
@@ -0,0 +1,3 @@
1
+ execute 'install' do
2
+ action :nothing
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'chefspec'
2
+
3
+ describe 'do_nothing::default' do
4
+ let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
5
+
6
+ it 'includes the `other` recipe' do
7
+ execute = chef_run.execute('install')
8
+ expect(execute).to do_nothing
9
+ end
10
+
11
+ it 'does not include the `not` recipe' do
12
+ execute = chef_run.execute('not_install')
13
+ expect(execute).to_not do_nothing
14
+ end
15
+ end
@@ -18,6 +18,15 @@ describe 'render_file::default' do
18
18
  expect(chef_run).to render_file('/tmp/file').with_content(/^This(.+)$/)
19
19
  expect(chef_run).to_not render_file('/tmp/file').with_content(/^Not(.+)$/)
20
20
  end
21
+
22
+ it 'renders the file with content matching arbitrary matcher' do
23
+ expect(chef_run).to render_file('/tmp/file').with_content(
24
+ start_with('This')
25
+ )
26
+ expect(chef_run).to_not render_file('/tmp/file').with_content(
27
+ end_with('not')
28
+ )
29
+ end
21
30
  end
22
31
 
23
32
  context 'cookbook_file' do
@@ -35,6 +44,15 @@ describe 'render_file::default' do
35
44
  expect(chef_run).to render_file('/tmp/cookbook_file').with_content(/^This(.+)$/)
36
45
  expect(chef_run).to_not render_file('/tmp/cookbook_file').with_content(/^Not(.+)$/)
37
46
  end
47
+
48
+ it 'renders the file with content matching arbitrary matcher' do
49
+ expect(chef_run).to render_file('/tmp/cookbook_file').with_content(
50
+ start_with('This')
51
+ )
52
+ expect(chef_run).to_not render_file('/tmp/cookbook_file').with_content(
53
+ end_with('not')
54
+ )
55
+ end
38
56
  end
39
57
 
40
58
  context 'template' do
@@ -52,6 +70,15 @@ describe 'render_file::default' do
52
70
  expect(chef_run).to render_file('/tmp/template').with_content(/^This(.+)$/)
53
71
  expect(chef_run).to_not render_file('/tmp/template').with_content(/^Not(.+)$/)
54
72
  end
73
+
74
+ it 'renders the file with content matching arbitrary matcher' do
75
+ expect(chef_run).to render_file('/tmp/template').with_content(
76
+ start_with('This')
77
+ )
78
+ expect(chef_run).to_not render_file('/tmp/template').with_content(
79
+ end_with('not')
80
+ )
81
+ end
55
82
  end
56
83
 
57
84
  context 'template with render' do
@@ -0,0 +1,10 @@
1
+ Feature: The do_nothing matcher
2
+ Background:
3
+ * I am using the "do_nothing" cookbook
4
+
5
+ Scenario Outline: Running specs
6
+ * I successfully run `rspec spec/<Matcher>_spec.rb`
7
+ * the output should contain "0 failures"
8
+ Examples:
9
+ | Matcher |
10
+ | default |
@@ -34,6 +34,7 @@ require_relative 'api/cron'
34
34
  require_relative 'api/deploy'
35
35
  require_relative 'api/directory'
36
36
  require_relative 'api/dpkg_package'
37
+ require_relative 'api/do_nothing'
37
38
  require_relative 'api/easy_install_package'
38
39
  require_relative 'api/env'
39
40
  require_relative 'api/erl_call'
@@ -0,0 +1,24 @@
1
+ module ChefSpec::API
2
+ # @since 3.4.0
3
+ module DoNothingMatchers
4
+ #
5
+ # Assert that a resource in the Chef run does not perform any actions. Given
6
+ # a resource with +action :nothing+:
7
+ #
8
+ # package 'apache2' do
9
+ # action :nothing
10
+ # end
11
+ #
12
+ # The Examples section demonstrates the different ways to test that no
13
+ # actions were performed on a resource in a Chef run.
14
+ #
15
+ # @example Assert the +package+ does not perform any actions
16
+ #
17
+ #
18
+ # @return [ChefSpec::Matchers::DoNothingMatcher]
19
+ #
20
+ def do_nothing
21
+ ChefSpec::Matchers::DoNothingMatcher.new
22
+ end
23
+ end
24
+ end
@@ -16,6 +16,9 @@ module ChefSpec::API
16
16
  # @example Assert a template is rendered with matching content
17
17
  # expect(template).to render_file('/etc/foo').with_content(/^This(.+)$/)
18
18
  #
19
+ # @example Assert a template is rendered with content matching any RSpec matcher
20
+ # expect(template).to render_file('/etc/foo').with_content(starts_with('This'))
21
+ #
19
22
  # @example Assert a partial path to a template is rendered with matching content
20
23
  # expect(template).to render_file(/\/etc\/foo-(\d+)$/).with_content(/^This(.+)$/)
21
24
  #
@@ -56,10 +56,14 @@ module ChefSpec
56
56
  .select(&:metadata?)
57
57
  .map(&:name)
58
58
  else
59
- berksfile.sources.select(&:location)
60
- .map(&:location)
61
- .select(&:metadata?)
62
- .map(&:name)
59
+ berksfile.sources.collect do |source|
60
+ location = source.location
61
+ if location.respond_to?(:metadata?) && location.metadata?
62
+ source
63
+ else
64
+ nil
65
+ end
66
+ end.compact.map(&:name)
63
67
  end
64
68
  end
65
69
 
@@ -1,5 +1,6 @@
1
1
  module ChefSpec
2
2
  module Matchers
3
+ require_relative 'matchers/do_nothing_matcher'
3
4
  require_relative 'matchers/include_recipe_matcher'
4
5
  require_relative 'matchers/link_to_matcher'
5
6
  require_relative 'matchers/notifications_matcher'
@@ -0,0 +1,50 @@
1
+ module ChefSpec::Matchers
2
+ class DoNothingMatcher
3
+ def matches?(resource)
4
+ @resource = resource
5
+
6
+ if @resource
7
+ actions = @resource.performed_actions
8
+ actions.empty? || actions == [:nothing]
9
+ else
10
+ false
11
+ end
12
+ end
13
+
14
+ def description
15
+ 'do nothing'
16
+ end
17
+
18
+ def failure_message_for_should
19
+ if @resource
20
+ message = %|expected #{@resource} to do nothing, but the following |
21
+ message << %|actions were performed:|
22
+ message << %|\n\n|
23
+ @resource.performed_actions.each do |action|
24
+ message << %| :#{action}|
25
+ end
26
+ message
27
+ else
28
+ message = %|expected _something_ to do nothing, but the _something_ |
29
+ message << %|you gave me was nil! If you are running a test like:|
30
+ message << %|\n\n|
31
+ message << %| expect(_something_).to do_nothing|
32
+ message << %|\n\n|
33
+ message << %|make sure that `_something_` exists, because I got nil!|
34
+ message
35
+ end
36
+ end
37
+
38
+ def failure_message_for_should_not
39
+ if @resource
40
+ message = %|expected #{@resource} to do something, but no actions |
41
+ message << %|were performed.|
42
+ message
43
+ else
44
+ message = %|expected _something_ to do something, but no actions |
45
+ message << %|were performed.|
46
+ message
47
+ end
48
+ end
49
+ end
50
+ end
@@ -53,7 +53,7 @@ module ChefSpec::Matchers
53
53
 
54
54
  def failure_message_for_should
55
55
  if @resource
56
- message = %Q{expected "#{resource_name(@resource)}[#{@resource.name}]" to notify "#{@expected_resource_type}[#{@expected_resource_name}]"}
56
+ message = %Q{expected "#{@resource}" to notify "#{@expected_resource_type}[#{@expected_resource_name}]"}
57
57
  message << " with action :#{@action}" if @action
58
58
  message << " immediately" if @immediately
59
59
  message << " delayed" if @delayed
@@ -77,6 +77,14 @@ module ChefSpec::Matchers
77
77
  end
78
78
  end
79
79
 
80
+ def failure_message_for_should_not
81
+ if @resource
82
+ message = %Q{expected "#{@resource}" to not notify "#{@expected_resource_type}[#{@expected_resource_name}]"}
83
+ message << ", but it did."
84
+ message
85
+ end
86
+ end
87
+
80
88
  private
81
89
 
82
90
  def all_notifications
@@ -29,9 +29,9 @@ module ChefSpec::Matchers
29
29
  def failure_message_for_should
30
30
  message = %Q{expected Chef run to render "#{@path}"}
31
31
  if @expected_content
32
- message << " with:"
32
+ message << " matching:"
33
33
  message << "\n\n"
34
- message << @expected_content.to_s
34
+ message << expected_content_message
35
35
  message << "\n\n"
36
36
  message << "but got:"
37
37
  message << "\n\n"
@@ -44,9 +44,9 @@ module ChefSpec::Matchers
44
44
  def failure_message_for_should_not
45
45
  message = %Q{expected file "#{@path}"}
46
46
  if @expected_content
47
- message << " with:"
47
+ message << " matching:"
48
48
  message << "\n\n"
49
- message << @expected_content.to_s
49
+ message << expected_content_message
50
50
  message << "\n\n"
51
51
  end
52
52
  message << " to not be in Chef run"
@@ -55,6 +55,14 @@ module ChefSpec::Matchers
55
55
 
56
56
  private
57
57
 
58
+ def expected_content_message
59
+ if RSpec::Matchers.is_a_matcher?(@expected_content) && @expected_content.respond_to?(:description)
60
+ @expected_content.description
61
+ else
62
+ @expected_content.to_s
63
+ end
64
+ end
65
+
58
66
  def resource
59
67
  @resource ||= @runner.find_resource(:cookbook_file, @path) ||
60
68
  @runner.find_resource(:file, @path) ||
@@ -88,6 +96,8 @@ module ChefSpec::Matchers
88
96
 
89
97
  if @expected_content.is_a?(Regexp)
90
98
  @actual_content =~ @expected_content
99
+ elsif RSpec::Matchers.is_a_matcher?(@expected_content)
100
+ @expected_content.matches?(@actual_content)
91
101
  else
92
102
  @actual_content.include?(@expected_content)
93
103
  end
@@ -55,5 +55,9 @@ module ChefSpec::Matchers
55
55
  def failure_message_for_should
56
56
  @instance.failure_message_for_should
57
57
  end
58
+
59
+ def failure_message_for_should_not
60
+ @instance.failure_message_for_should_not
61
+ end
58
62
  end
59
63
  end
@@ -1,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '3.3.1'
2
+ VERSION = '3.4.0'
3
3
  end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ChefSpec::Matchers::DoNothingMatcher do
4
+ pending
5
+ end
@@ -1,5 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ChefSpec::Matchers::NotificationsMatcher do
4
- pending
4
+ subject { described_class.new('execute[install]') }
5
+ let(:package) do
6
+ double('package',
7
+ name: 'package',
8
+ to_s: 'package[foo]',
9
+ is_a?: true,
10
+ performed_action?: true,
11
+ immediate_notifications: [],
12
+ delayed_notifications: [],
13
+ )
14
+ end
15
+
16
+ describe '#failure_message_for_should' do
17
+ it 'has the right value' do
18
+ subject.matches?(package)
19
+ expect(subject.failure_message_for_should)
20
+ .to include %|expected "package[foo]" to notify "execute[install]", but did not.|
21
+ end
22
+ end
23
+
24
+ describe '#failure_message_for_should_not' do
25
+ it 'has the right value' do
26
+ subject.matches?(package)
27
+ expect(subject.failure_message_for_should_not)
28
+ .to eq %|expected "package[foo]" to not notify "execute[install]", but it did.|
29
+ end
30
+ end
31
+
32
+ describe '#description' do
33
+ it 'has the right value' do
34
+ subject.matches?(package)
35
+ expect(subject.description)
36
+ .to eq %|notify "execute[install]"|
37
+ end
38
+ end
5
39
  end
@@ -1,5 +1,64 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ChefSpec::Matchers::SubscribesMatcher do
4
- pending
4
+ subject { described_class.new('execute[install]') }
5
+ let(:runner) { double('runner', find_resource: nil) }
6
+ let(:run_context) { double('run_context', node: node) }
7
+ let(:node) { double('node', runner: runner) }
8
+ let(:package) do
9
+ double('package',
10
+ name: 'package',
11
+ to_s: 'package[foo]',
12
+ run_context: run_context,
13
+ )
14
+ end
15
+
16
+ context 'when no resource is found' do
17
+ describe '#failure_message_for_should' do
18
+ it 'has the right value' do
19
+ subject.matches?(package)
20
+ expect(subject.failure_message_for_should)
21
+ .to include %|expected _something_ to notify "package[foo]", but the _something_ you gave me was nil! If you are running a test like:|
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'when the resource exists' do
27
+ let(:execute) do
28
+ double('execute',
29
+ name: 'execute',
30
+ to_s: 'execute[install]',
31
+ immediate_notifications: [],
32
+ delayed_notifications: [],
33
+ )
34
+ end
35
+
36
+ before do
37
+ runner.stub(:find_resource).and_return(execute)
38
+ end
39
+
40
+ describe '#failure_message_for_should' do
41
+ it 'has the right value' do
42
+ subject.matches?(package)
43
+ expect(subject.failure_message_for_should)
44
+ .to include %|expected "execute[install]" to notify "package[foo]", but did not.|
45
+ end
46
+ end
47
+
48
+ describe '#failure_message_for_should_not' do
49
+ it 'has the right value' do
50
+ subject.matches?(package)
51
+ expect(subject.failure_message_for_should_not)
52
+ .to eq %|expected "execute[install]" to not notify "package[foo]", but it did.|
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#description' do
58
+ it 'has the right value' do
59
+ subject.matches?(package)
60
+ expect(subject.description)
61
+ .to eq %|notify "package[foo]"|
62
+ end
63
+ end
5
64
  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: 3.3.1
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Crump
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-11 00:00:00.000000000 Z
12
+ date: 2014-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -201,6 +201,8 @@ files:
201
201
  - examples/directory/recipes/delete.rb
202
202
  - examples/directory/spec/create_spec.rb
203
203
  - examples/directory/spec/delete_spec.rb
204
+ - examples/do_nothing/recipes/default.rb
205
+ - examples/do_nothing/spec/default_spec.rb
204
206
  - examples/dpkg_package/recipes/install.rb
205
207
  - examples/dpkg_package/recipes/purge.rb
206
208
  - examples/dpkg_package/recipes/remove.rb
@@ -553,6 +555,7 @@ files:
553
555
  - features/custom_matcher.feature
554
556
  - features/deploy.feature
555
557
  - features/directory.feature
558
+ - features/do_nothing.feature
556
559
  - features/dpkg_package.feature
557
560
  - features/easy_install_package.feature
558
561
  - features/env.feature
@@ -628,6 +631,7 @@ files:
628
631
  - lib/chefspec/api/cron.rb
629
632
  - lib/chefspec/api/deploy.rb
630
633
  - lib/chefspec/api/directory.rb
634
+ - lib/chefspec/api/do_nothing.rb
631
635
  - lib/chefspec/api/dpkg_package.rb
632
636
  - lib/chefspec/api/easy_install_package.rb
633
637
  - lib/chefspec/api/env.rb
@@ -687,6 +691,7 @@ files:
687
691
  - lib/chefspec/librarian.rb
688
692
  - lib/chefspec/macros.rb
689
693
  - lib/chefspec/matchers.rb
694
+ - lib/chefspec/matchers/do_nothing_matcher.rb
690
695
  - lib/chefspec/matchers/include_recipe_matcher.rb
691
696
  - lib/chefspec/matchers/link_to_matcher.rb
692
697
  - lib/chefspec/matchers/notifications_matcher.rb
@@ -719,6 +724,7 @@ files:
719
724
  - spec/unit/expect_exception_spec.rb
720
725
  - spec/unit/extensions/lwrp_base_spec.rb
721
726
  - spec/unit/macros_spec.rb
727
+ - spec/unit/matchers/do_nothing_matcher.rb
722
728
  - spec/unit/matchers/include_recipe_matcher_spec.rb
723
729
  - spec/unit/matchers/link_to_matcher_spec.rb
724
730
  - spec/unit/matchers/notifications_matcher_spec.rb
@@ -778,6 +784,7 @@ test_files:
778
784
  - features/custom_matcher.feature
779
785
  - features/deploy.feature
780
786
  - features/directory.feature
787
+ - features/do_nothing.feature
781
788
  - features/dpkg_package.feature
782
789
  - features/easy_install_package.feature
783
790
  - features/env.feature
@@ -846,6 +853,7 @@ test_files:
846
853
  - spec/unit/expect_exception_spec.rb
847
854
  - spec/unit/extensions/lwrp_base_spec.rb
848
855
  - spec/unit/macros_spec.rb
856
+ - spec/unit/matchers/do_nothing_matcher.rb
849
857
  - spec/unit/matchers/include_recipe_matcher_spec.rb
850
858
  - spec/unit/matchers/link_to_matcher_spec.rb
851
859
  - spec/unit/matchers/notifications_matcher_spec.rb