chefspec 4.1.1 → 4.2.0.beta.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b27856f904afc7828e2ebd18d3b0d6cf445df4c
4
- data.tar.gz: c044c2653ce2dd4edea1a9af3be1a279bd10464b
3
+ metadata.gz: 68b2b322b2293fa631345ed68a61262d0f46d943
4
+ data.tar.gz: 99a905d8ea24d4c6d20f554c8bc0f42d5f60f14f
5
5
  SHA512:
6
- metadata.gz: b990fc3a58d92ab8a308ae89fe1f4c354f513d3af9054dc2e328df7fb88313c7a539117ab58ece8775d39f3aff296de8c4c20a6b36e94f6a6a1ad6d4f9832dec
7
- data.tar.gz: b4fa0c0393da51a776b26b7c2da7b55cedda9d6c5f27747475feb229797c3d6eaaaf1abf79d70991ff7f6f00256761b91cdb9eff17ef5626db9e2440b29c5670
6
+ metadata.gz: 07409059ef229f4eb9e2e7f9fe3d4f1d9db2b9e859f0864fbc29df6ed89fddf1e60788e9d7808aae2c853d6ed52163be242ecb99b55ff410327a958b95310883
7
+ data.tar.gz: 7153ec068c65759290deadf4183d3a57693b092a531118ce4b3f1294f2fa4b2d056202ff2fa4f3c83397db7fc9bb5d2fb92c1a4f5b02fc502d612500c39a8c37
data/.travis.yml CHANGED
@@ -21,11 +21,10 @@ bundler_args: --jobs 7
21
21
  gemfile:
22
22
  - gemfiles/chef-11.14.0.gemfile
23
23
  - gemfiles/chef-11.16.0.gemfile
24
- - gemfiles/chef-12.0.0.alpha.gemfile
24
+ - gemfiles/chef-12.0.0.rc.gemfile
25
25
  - gemfiles/chef-master.gemfile
26
26
 
27
27
  matrix:
28
28
  fast_finish: true
29
29
  allow_failures:
30
- - gemfile: gemfiles/chef-12.0.0.alpha.gemfile
31
30
  - gemfile: gemfiles/chef-master.gemfile
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  CHANGELOG for ChefSpec
2
2
  ======================
3
3
 
4
+ ## 4.2.0.beta.1 (November 5, 2014)
5
+ Bugfixes:
6
+ - Updated README grep examples
7
+ - Fix various typographical errors
8
+ - Improved error message when using a deprecated resource matcher
9
+
10
+ Improvements:
11
+ - Add support for Chef 12
12
+ - Added support for environments in Chef Solo
13
+
4
14
  ## 4.1.1 (October 13, 2014)
5
15
  Bugfixes:
6
16
  - Fix total fail on my part with deprecations and add test coverage
data/README.md CHANGED
@@ -81,6 +81,9 @@ RSpec.configure do |config|
81
81
  # Specify the path for Chef Solo to find roles (default: [ascending search])
82
82
  config.role_path = '/var/roles'
83
83
 
84
+ # Specify the path for Chef Solo to find environments (default: [ascending search])
85
+ config.environment_path = '/var/environments'
86
+
84
87
  # Specify the Chef log_level (default: :warn)
85
88
  config.log_level = :debug
86
89
 
@@ -437,18 +440,18 @@ Given a recipe with shell guard:
437
440
 
438
441
  ```ruby
439
442
  template '/tmp/foo.txt' do
440
- not_if 'grep /tmp/foo.txt text'
443
+ not_if 'grep text /tmp/foo.txt'
441
444
  end
442
445
  ```
443
446
 
444
447
  ChefSpec will raise an error like:
445
448
 
446
449
  ```text
447
- Real commands are disabled. Unregistered command: `grep /tmp/foo.txt text`
450
+ Real commands are disabled. Unregistered command: `grep text /tmp/foo.txt`
448
451
 
449
452
  You can stub this command with:
450
453
 
451
- stub_command("grep /tmp/foo.txt text").and_return(true)
454
+ stub_command("grep text /tmp/foo.txt").and_return(true)
452
455
 
453
456
  ============================================================
454
457
  ```
@@ -460,7 +463,7 @@ describe 'example::default' do
460
463
  let(:chef_run) { ChefSpec::SoloRunner.new }
461
464
 
462
465
  before do
463
- stub_command("grep /tmp/foo.txt text").and_return(true)
466
+ stub_command("grep text /tmp/foo.txt").and_return(true)
464
467
  end
465
468
  end
466
469
  ```
@@ -470,7 +473,7 @@ describe 'example::default' do
470
473
  let(:chef_run) { ChefSpec::SoloRunner.new }
471
474
 
472
475
  before do
473
- stub_command("grep /tmp/foo.txt text") { rand(50)%2 == 0 }
476
+ stub_command("grep text /tmp/foo.txt") { rand(50)%2 == 0 }
474
477
  end
475
478
  end
476
479
  ```
@@ -6,7 +6,7 @@ if defined?(ChefSpec)
6
6
  # documentation indicating how to use the custom matcher.
7
7
  #
8
8
  # @example This is an example
9
- # expect(chef_run.to install_custom_matcher_thing('foo')
9
+ # expect(chef_run).to install_custom_matcher_thing('foo')
10
10
  #
11
11
  # @param [String] resource_name
12
12
  # the resource name
@@ -1,3 +1,4 @@
1
+ @not_chef_12_0_0_rc_0
1
2
  Feature: The inherits matcher
2
3
  Background:
3
4
  * I am using the "inherits" cookbook
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'chef', '~> 12.0.0.alpha'
3
+ gem 'chef', '~> 12.0.0.rc'
4
4
 
5
5
  gemspec :path => '..'
data/lib/chefspec.rb CHANGED
@@ -80,3 +80,4 @@ require_relative 'chefspec/util'
80
80
  require_relative 'chefspec/version'
81
81
 
82
82
  require_relative 'chefspec/deprecations'
83
+ require_relative 'chefspec/chef_backwards_compat' if Chef::VERSION.to_f < 12.0
@@ -0,0 +1,79 @@
1
+ #
2
+ # This file contains the backwards compatible hacks required to make ChefSpec
3
+ # work with the previous version of Chef. ChefSpec only promises to be backwards
4
+ # compatible with the last major release of Chef, but it may work with earlier
5
+ # versions.
6
+ #
7
+ # The hacks are kept in this file so as to avoid a bunch of branching logic
8
+ # throughout the codebase. It also makes dropping backwards compatability much
9
+ # easier without the risk of breaking things.
10
+ #
11
+ # This file must be loaded AFTER the rest of ChefSpec has been initialized!
12
+ #
13
+
14
+ module ChefSpec
15
+ class ServerRunner
16
+ #
17
+ # The method airty for the Chef::CookbookUploader used to accept a list of
18
+ # cookbook paths. This restores that behavior.
19
+ #
20
+ def cookbook_uploader_for(loader)
21
+ Chef::CookbookUploader.new(loader.cookbooks, loader.cookbook_paths)
22
+ end
23
+ end
24
+
25
+ module RemoveExistingLWRP
26
+ def self.extended(klass)
27
+ class << klass
28
+ alias_method :build_from_file_without_removal, :build_from_file
29
+ alias_method :build_from_file, :build_from_file_with_removal
30
+ end
31
+ end
32
+
33
+ #
34
+ # Override Chef provider to remove any existing LWRPs to suppress constant
35
+ # re-definition warnings.
36
+ #
37
+ # @param [String] cookbook_name
38
+ # the name of the cookbook
39
+ # @param [String] filename
40
+ # file to load as a LWRP
41
+ # @param [Chef::RunContext] run_context
42
+ # context of a Chef Run
43
+ #
44
+ # @return [Chef::Provider]
45
+ #
46
+ def build_from_file_with_removal(cookbook_name, filename, run_context)
47
+ provider_name = filename_to_qualified_string(cookbook_name, filename)
48
+ class_name = convert_to_class_name(provider_name)
49
+
50
+ remove_existing_lwrp(class_name)
51
+ build_from_file_without_removal(cookbook_name, filename, run_context)
52
+ end
53
+
54
+ #
55
+ # Remove any existing Chef provider or resource with the specified name.
56
+ #
57
+ # @param [String] class_name
58
+ # The class name. Must be a valid constant name.
59
+ #
60
+ def remove_existing_lwrp(class_name)
61
+ [self, superclass].each do |resource_holder|
62
+ look_in_parents = false
63
+ if resource_holder.const_defined?(class_name, look_in_parents)
64
+ old_class = resource_holder.send(:remove_const, class_name)
65
+
66
+ if resource_holder.respond_to?(:resource_classes)
67
+ resource_holder.resource_classes.delete(old_class)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+
76
+ # Only remove existing LWRPs for older versions of Chef. Newer versions of
77
+ # Chef do not break things as much...
78
+ Chef::Provider::LWRPBase.extend(ChefSpec::RemoveExistingLWRP)
79
+ Chef::Resource::LWRPBase.extend(ChefSpec::RemoveExistingLWRP)
@@ -20,6 +20,7 @@ module ChefSpec
20
20
  # use {ChefSpec.define_runner_method} instead.
21
21
  def self.define_runner_method(resource_name)
22
22
  deprecated "`ChefSpec::Runner.define_runner_method' is deprecated. " \
23
+ "It is being used in the #{resource_name} resource matcher." \
23
24
  "Please use `ChefSpec.define_matcher' instead."
24
25
 
25
26
  ChefSpec.define_matcher(resource_name)
@@ -1,59 +1,7 @@
1
1
  # Override Chef LWRP creation to remove existing class to avoid redefinition warnings.
2
2
  class Chef
3
- module RemoveExistingLWRP
4
- def self.extended(klass)
5
- class << klass
6
- alias_method :build_from_file_without_removal, :build_from_file
7
- alias_method :build_from_file, :build_from_file_with_removal
8
- end
9
- end
10
-
11
- #
12
- # Override Opscode provider to remove any existing LWRPs to suppress
13
- # constant re-definition warnings.
14
- #
15
- # @param [String] cookbook_name
16
- # the name of the cookbook
17
- # @param [String] filename
18
- # file to load as a LWRP
19
- # @param [Chef::RunContext] run_context
20
- # context of a Chef Run
21
- #
22
- # @return [Chef::Provider]
23
- #
24
- def build_from_file_with_removal(cookbook_name, filename, run_context)
25
- provider_name = filename_to_qualified_string(cookbook_name, filename)
26
- class_name = convert_to_class_name(provider_name)
27
-
28
- remove_existing_lwrp(class_name)
29
- build_from_file_without_removal(cookbook_name, filename, run_context)
30
- end
31
-
32
- #
33
- # Remove any existing Chef provider or resource with the specified name.
34
- #
35
- # @param [String] class_name
36
- # The class name. Must be a valid constant name.
37
- #
38
- def remove_existing_lwrp(class_name)
39
- [self, superclass].each do |resource_holder|
40
- look_in_parents = false
41
- if resource_holder.const_defined?(class_name, look_in_parents)
42
- old_class = resource_holder.send(:remove_const, class_name)
43
-
44
- if resource_holder.respond_to?(:resource_classes)
45
- resource_holder.resource_classes.delete(old_class)
46
- end
47
- end
48
- end
49
- end
50
- end
51
-
52
3
  class Provider
53
- # Chef provider for a resource
54
4
  class LWRPBase < Provider
55
- extend RemoveExistingLWRP
56
-
57
5
  module InlineResources
58
6
  module ClassMethods
59
7
  #
@@ -72,11 +20,4 @@ class Chef
72
20
  end
73
21
  end
74
22
  end
75
-
76
- class Resource
77
- # Chef provider for a resource
78
- class LWRPBase < Resource
79
- extend RemoveExistingLWRP
80
- end
81
- end
82
23
  end
@@ -11,6 +11,7 @@ RSpec.configure do |config|
11
11
 
12
12
  config.add_setting :cookbook_path
13
13
  config.add_setting :role_path
14
+ config.add_setting :environment_path
14
15
  config.add_setting :log_level, default: :warn
15
16
  config.add_setting :path
16
17
  config.add_setting :platform
@@ -38,9 +38,19 @@ module ChefSpec
38
38
  def upload_cookbooks!
39
39
  loader = Chef::CookbookLoader.new(Chef::Config[:cookbook_path])
40
40
  loader.load_cookbooks
41
+ cookbook_uploader_for(loader).upload_cookbooks
42
+ end
41
43
 
42
- uploader = Chef::CookbookUploader.new(loader.cookbooks, loader.cookbook_paths)
43
- uploader.upload_cookbooks
44
+ #
45
+ # The uploader for the cookbooks.
46
+ #
47
+ # @param [Chef::CookbookLoader] loader
48
+ # the Chef cookbook loader
49
+ #
50
+ # @return [Chef::CookbookUploader]
51
+ #
52
+ def cookbook_uploader_for(loader)
53
+ Chef::CookbookUploader.new(loader.cookbooks)
44
54
  end
45
55
 
46
56
  # @see (SoloRunner#converge)
@@ -77,6 +77,7 @@ module ChefSpec
77
77
  Chef::Config[:role_path] = Array(@options[:role_path])
78
78
  Chef::Config[:force_logger] = true
79
79
  Chef::Config[:solo] = true
80
+ Chef::Config[:environment_path] = @options[:environment_path]
80
81
 
81
82
  yield node if block_given?
82
83
  end
@@ -301,6 +302,7 @@ module ChefSpec
301
302
  {
302
303
  cookbook_path: config.cookbook_path || calling_cookbook_path(caller),
303
304
  role_path: config.role_path || default_role_path,
305
+ environment_path: config.environment_path || default_environment_path,
304
306
  log_level: config.log_level,
305
307
  path: config.path,
306
308
  platform: config.platform,
@@ -340,6 +342,20 @@ module ChefSpec
340
342
  nil
341
343
  end
342
344
 
345
+ #
346
+ # The inferred path to environments.
347
+ #
348
+ # @return [String, nil]
349
+ #
350
+ def default_environment_path
351
+ Pathname.new(Dir.pwd).ascend do |path|
352
+ possible = File.join(path, 'environments')
353
+ return possible if File.exist?(possible)
354
+ end
355
+
356
+ nil
357
+ end
358
+
343
359
  #
344
360
  # The +Chef::Client+ for this runner.
345
361
  #
@@ -1,3 +1,3 @@
1
1
  module ChefSpec
2
- VERSION = '4.1.1'
2
+ VERSION = '4.2.0.beta.1'
3
3
  end
@@ -16,6 +16,7 @@ describe ChefSpec::Runner do
16
16
  it 'prints a deprecation' do
17
17
  expect(ChefSpec::Runner).to receive(:deprecated)
18
18
  .with("`ChefSpec::Runner.define_runner_method' is deprecated. "\
19
+ "It is being used in the my_custom_resource resource matcher." \
19
20
  "Please use `ChefSpec.define_matcher' instead.")
20
21
  ChefSpec::Runner.define_runner_method(:my_custom_resource)
21
22
  end
@@ -1,8 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- # Don't run this test on older versions of Chef
4
- if Chef::VERSION >= '11.0.0'
5
-
3
+ # Chef 12 fixed resource inheritance issues
4
+ if Chef::VERSION.to_f < 12.0
6
5
  module ChefSpec
7
6
  module Extensions
8
7
  describe :LWRPBase do
@@ -104,6 +104,7 @@ describe ChefSpec::SoloRunner do
104
104
  context 'RSpec global configuration' do
105
105
  before do
106
106
  allow(RSpec.configuration).to receive(:cookbook_path).and_return('./path')
107
+ allow(RSpec.configuration).to receive(:environment_path).and_return('./env-path')
107
108
  allow(RSpec.configuration).to receive(:log_level).and_return(:fatal)
108
109
  allow(RSpec.configuration).to receive(:path).and_return('ohai.json')
109
110
  allow(RSpec.configuration).to receive(:platform).and_return('ubuntu')
@@ -113,6 +114,7 @@ describe ChefSpec::SoloRunner do
113
114
  it 'uses the RSpec values' do
114
115
  options = described_class.new.options
115
116
  expect(options[:cookbook_path]).to eq('./path')
117
+ expect(options[:environment_path]).to eq('./env-path')
116
118
  expect(options[:log_level]).to eq(:fatal)
117
119
  expect(options[:path]).to eq('ohai.json')
118
120
  expect(options[:platform]).to eq('ubuntu')
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: 4.1.1
4
+ version: 4.2.0.beta.1
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-10-13 00:00:00.000000000 Z
12
+ date: 2014-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -606,7 +606,7 @@ files:
606
606
  - features/yum_package.feature
607
607
  - gemfiles/chef-11.14.0.gemfile
608
608
  - gemfiles/chef-11.16.0.gemfile
609
- - gemfiles/chef-12.0.0.alpha.gemfile
609
+ - gemfiles/chef-12.0.0.rc.gemfile
610
610
  - gemfiles/chef-master.gemfile
611
611
  - lib/chefspec.rb
612
612
  - lib/chefspec/api.rb
@@ -662,6 +662,7 @@ files:
662
662
  - lib/chefspec/api/yum_package.rb
663
663
  - lib/chefspec/berkshelf.rb
664
664
  - lib/chefspec/cacher.rb
665
+ - lib/chefspec/chef_backwards_compat.rb
665
666
  - lib/chefspec/coverage.rb
666
667
  - lib/chefspec/coverage/filters.rb
667
668
  - lib/chefspec/deprecations.rb
@@ -755,12 +756,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
755
756
  version: '1.9'
756
757
  required_rubygems_version: !ruby/object:Gem::Requirement
757
758
  requirements:
758
- - - ">="
759
+ - - ">"
759
760
  - !ruby/object:Gem::Version
760
- version: '0'
761
+ version: 1.3.1
761
762
  requirements: []
762
763
  rubyforge_project:
763
- rubygems_version: 2.3.0
764
+ rubygems_version: 2.2.2
764
765
  signing_key:
765
766
  specification_version: 4
766
767
  summary: Write RSpec examples and generate coverage reports for Chef recipes!