chefspec 4.2.0 → 4.7.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +39 -16
- data/CHANGELOG.md +136 -72
- data/README.md +187 -13
- data/chefspec.gemspec +5 -5
- data/examples/batch/spec/run_spec.rb +5 -0
- data/examples/chef_gem/recipes/install.rb +8 -3
- data/examples/chef_gem/recipes/purge.rb +6 -3
- data/examples/chef_gem/recipes/reconfig.rb +6 -3
- data/examples/chef_gem/recipes/remove.rb +6 -3
- data/examples/chef_gem/recipes/upgrade.rb +6 -3
- data/examples/chocolatey_package/recipes/install.rb +6 -0
- data/examples/chocolatey_package/recipes/remove.rb +8 -0
- data/examples/chocolatey_package/recipes/upgrade.rb +8 -0
- data/examples/chocolatey_package/spec/install_spec.rb +21 -0
- data/examples/chocolatey_package/spec/remove_spec.rb +20 -0
- data/examples/chocolatey_package/spec/upgrade_spec.rb +20 -0
- data/examples/directory/recipes/create.rb +4 -0
- data/examples/directory/spec/create_spec.rb +4 -0
- data/examples/dpkg_package/spec/install_spec.rb +5 -0
- data/examples/dpkg_package/spec/purge_spec.rb +5 -0
- data/examples/dpkg_package/spec/remove_spec.rb +5 -0
- data/examples/dsc_resource/recipes/default.rb +20 -0
- data/examples/dsc_resource/spec/default_spec.rb +40 -0
- data/examples/env/spec/create_spec.rb +5 -0
- data/examples/env/spec/delete_spec.rb +5 -0
- data/examples/env/spec/modify_spec.rb +5 -0
- data/examples/ips_package/spec/install_spec.rb +5 -0
- data/examples/ips_package/spec/remove_spec.rb +5 -0
- data/examples/ips_package/spec/upgrade_spec.rb +5 -0
- data/examples/package/recipes/install.rb +4 -0
- data/examples/package/recipes/purge.rb +4 -0
- data/examples/package/recipes/reconfig.rb +4 -0
- data/examples/package/recipes/remove.rb +4 -0
- data/examples/package/recipes/upgrade.rb +4 -0
- data/examples/package/spec/install_spec.rb +4 -0
- data/examples/package/spec/purge_spec.rb +4 -0
- data/examples/package/spec/reconfig_spec.rb +4 -0
- data/examples/package/spec/remove_spec.rb +4 -0
- data/examples/package/spec/upgrade_spec.rb +4 -0
- data/examples/pacman_package/spec/install_spec.rb +5 -0
- data/examples/pacman_package/spec/purge_spec.rb +5 -0
- data/examples/pacman_package/spec/remove_spec.rb +5 -0
- data/examples/pacman_package/spec/upgrade_spec.rb +5 -0
- data/examples/powershell_script/spec/run_spec.rb +5 -0
- data/examples/reboot/recipes/cancel.rb +3 -0
- data/examples/reboot/recipes/now.rb +3 -0
- data/examples/reboot/recipes/request.rb +3 -0
- data/examples/reboot/spec/cancel_spec.rb +10 -0
- data/examples/reboot/spec/now_spec.rb +10 -0
- data/examples/reboot/spec/request_spec.rb +10 -0
- data/examples/render_file/spec/default_spec.rb +40 -0
- data/examples/rpm_package/spec/install_spec.rb +5 -0
- data/examples/rpm_package/spec/remove_spec.rb +5 -0
- data/examples/rpm_package/spec/upgrade_spec.rb +5 -0
- data/examples/server/spec/node_spec.rb +1 -1
- data/examples/server/spec/search_spec.rb +4 -0
- data/examples/step_into/providers/provides.rb +3 -0
- data/examples/step_into/recipes/default.rb +2 -0
- data/examples/step_into/resources/lwrp.rb +1 -1
- data/examples/step_into/resources/provides.rb +6 -0
- data/examples/step_into/spec/default_spec.rb +10 -2
- data/examples/windows_package/recipes/install.rb +13 -0
- data/examples/windows_package/recipes/remove.rb +13 -0
- data/examples/windows_package/spec/install_spec.rb +24 -0
- data/examples/windows_package/spec/remove_spec.rb +24 -0
- data/examples/windows_service/recipes/configure_startup.rb +13 -0
- data/examples/windows_service/recipes/disable.rb +13 -0
- data/examples/windows_service/recipes/enable.rb +13 -0
- data/examples/windows_service/recipes/reload.rb +13 -0
- data/examples/windows_service/recipes/restart.rb +13 -0
- data/examples/windows_service/recipes/start.rb +13 -0
- data/examples/windows_service/recipes/stop.rb +13 -0
- data/examples/windows_service/spec/configure_startup_spec.rb +24 -0
- data/examples/windows_service/spec/disable_spec.rb +24 -0
- data/examples/windows_service/spec/enable_spec.rb +24 -0
- data/examples/windows_service/spec/reload_spec.rb +24 -0
- data/examples/windows_service/spec/restart_spec.rb +24 -0
- data/examples/windows_service/spec/start_spec.rb +24 -0
- data/examples/windows_service/spec/stop_spec.rb +24 -0
- data/features/chocolatey_package.feature +29 -0
- data/features/dsc_resource.feature +18 -0
- data/features/reboot.feature +19 -0
- data/features/step_definitions/background_steps.rb +4 -1
- data/features/step_into.feature +7 -0
- data/features/support/env.rb +5 -4
- data/features/windows_package.feature +24 -0
- data/features/windows_service.feature +23 -0
- data/gemfiles/chefspec.gemfile +9 -0
- data/lib/chefspec/api/chocolatey_package.rb +107 -0
- data/lib/chefspec/api/directory.rb +10 -10
- data/lib/chefspec/api/dsc_resource.rb +49 -0
- data/lib/chefspec/api/group.rb +5 -5
- data/lib/chefspec/api/link.rb +10 -10
- data/lib/chefspec/api/mdadm.rb +5 -5
- data/lib/chefspec/api/reboot.rb +18 -0
- data/lib/chefspec/api/remote_directory.rb +10 -10
- data/lib/chefspec/api/route.rb +5 -5
- data/lib/chefspec/api/user.rb +5 -5
- data/lib/chefspec/api/windows_package.rb +86 -0
- data/lib/chefspec/api/windows_service.rb +286 -0
- data/lib/chefspec/api.rb +5 -0
- data/lib/chefspec/berkshelf.rb +7 -1
- data/lib/chefspec/coverage/filters.rb +2 -1
- data/lib/chefspec/coverage.rb +1 -1
- data/lib/chefspec/deprecations.rb +6 -2
- data/lib/chefspec/errors.rb +4 -0
- data/lib/chefspec/extensions/chef/lwrp_base.rb +23 -0
- data/lib/chefspec/file_cache_path_proxy.rb +15 -0
- data/lib/chefspec/matchers/render_file_matcher.rb +20 -2
- data/lib/chefspec/matchers/resource_matcher.rb +9 -2
- data/lib/chefspec/mixins/normalize.rb +7 -1
- data/lib/chefspec/policyfile.rb +62 -0
- data/lib/chefspec/renderer.rb +2 -4
- data/lib/chefspec/rspec.rb +3 -0
- data/lib/chefspec/server_methods.rb +1 -0
- data/lib/chefspec/server_runner.rb +9 -0
- data/lib/chefspec/solo_runner.rb +13 -3
- data/lib/chefspec/version.rb +1 -1
- data/lib/chefspec.rb +1 -1
- data/spec/unit/coverage/filters_spec.rb +60 -0
- data/spec/unit/deprecations_spec.rb +3 -1
- data/spec/unit/macros_spec.rb +1 -1
- data/spec/unit/matchers/render_file_matcher_spec.rb +11 -0
- data/spec/unit/renderer_spec.rb +20 -2
- data/spec/unit/server_runner_spec.rb +28 -0
- data/spec/unit/solo_runner_spec.rb +3 -1
- data/templates/errors/invalid_berkshelf_options.erb +4 -0
- data/templates/errors/may_need_to_specify_platform.erb +25 -0
- metadata +72 -18
- data/gemfiles/chef-11.14.0.gemfile +0 -5
- data/gemfiles/chef-11.16.0.gemfile +0 -5
- data/gemfiles/chef-12.0.0.gemfile +0 -5
- data/gemfiles/chef-master.gemfile +0 -5
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
module ChefSpec::Matchers
|
|
2
2
|
class RenderFileMatcher
|
|
3
|
+
attr_reader :expected_content
|
|
3
4
|
def initialize(path)
|
|
4
5
|
@path = path
|
|
5
6
|
end
|
|
@@ -15,8 +16,17 @@ module ChefSpec::Matchers
|
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
def with_content(expected_content)
|
|
19
|
-
|
|
19
|
+
def with_content(expected_content = nil, &block)
|
|
20
|
+
if expected_content && block
|
|
21
|
+
raise ArgumentError, "Cannot specify expected content and a block!"
|
|
22
|
+
elsif expected_content
|
|
23
|
+
@expected_content = expected_content
|
|
24
|
+
elsif block_given?
|
|
25
|
+
@expected_content = block
|
|
26
|
+
else
|
|
27
|
+
raise ArgumentError, "Must specify expected content or a block!"
|
|
28
|
+
end
|
|
29
|
+
|
|
20
30
|
self
|
|
21
31
|
end
|
|
22
32
|
|
|
@@ -64,6 +74,8 @@ module ChefSpec::Matchers
|
|
|
64
74
|
def expected_content_message
|
|
65
75
|
if RSpec::Matchers.is_a_matcher?(@expected_content) && @expected_content.respond_to?(:description)
|
|
66
76
|
@expected_content.description
|
|
77
|
+
elsif @expected_content.is_a?(Proc)
|
|
78
|
+
"(the result of a proc)"
|
|
67
79
|
else
|
|
68
80
|
@expected_content.to_s
|
|
69
81
|
end
|
|
@@ -104,6 +116,12 @@ module ChefSpec::Matchers
|
|
|
104
116
|
@actual_content =~ @expected_content
|
|
105
117
|
elsif RSpec::Matchers.is_a_matcher?(@expected_content)
|
|
106
118
|
@expected_content.matches?(@actual_content)
|
|
119
|
+
elsif @expected_content.is_a?(Proc)
|
|
120
|
+
@expected_content.call(@actual_content)
|
|
121
|
+
# Weird RSpecish, but that block will return false for a negated check,
|
|
122
|
+
# so we always return true. The block will raise an exception if the
|
|
123
|
+
# assertion fails.
|
|
124
|
+
true
|
|
107
125
|
else
|
|
108
126
|
@actual_content.include?(@expected_content)
|
|
109
127
|
end
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'rspec/matchers/expecteds_for_multiple_diffs'
|
|
2
|
+
require 'rspec/expectations/fail_with'
|
|
3
|
+
|
|
1
4
|
module ChefSpec::Matchers
|
|
2
5
|
class ResourceMatcher
|
|
3
6
|
def initialize(resource_name, expected_action, expected_identity)
|
|
@@ -60,10 +63,14 @@ module ChefSpec::Matchers
|
|
|
60
63
|
%Q{expected "#{resource.to_s}" to be run at converge time}
|
|
61
64
|
end
|
|
62
65
|
else
|
|
63
|
-
%Q{expected "#{resource.to_s}" to have parameters:} \
|
|
66
|
+
message = %Q{expected "#{resource.to_s}" to have parameters:} \
|
|
64
67
|
"\n\n" \
|
|
65
68
|
" " + unmatched_parameters.collect { |parameter, h|
|
|
66
|
-
"#{parameter} #{h[:expected].inspect}, was #{h[:actual].inspect}"
|
|
69
|
+
msg = "#{parameter} #{h[:expected].inspect}, was #{h[:actual].inspect}"
|
|
70
|
+
diff = ::RSpec::Matchers::ExpectedsForMultipleDiffs.from(h[:expected]) \
|
|
71
|
+
.message_with_diff(message, ::RSpec::Expectations::differ, h[:actual])
|
|
72
|
+
msg += diff if diff
|
|
73
|
+
msg
|
|
67
74
|
}.join("\n ")
|
|
68
75
|
end
|
|
69
76
|
else
|
|
@@ -9,7 +9,13 @@ module ChefSpec
|
|
|
9
9
|
# @return [Symbol]
|
|
10
10
|
#
|
|
11
11
|
def resource_name(thing)
|
|
12
|
-
|
|
12
|
+
if thing.respond_to?(:declared_type) && thing.declared_type
|
|
13
|
+
name = thing.declared_type
|
|
14
|
+
elsif thing.respond_to?(:resource_name)
|
|
15
|
+
name = thing.resource_name
|
|
16
|
+
else
|
|
17
|
+
name = thing
|
|
18
|
+
end
|
|
13
19
|
name.to_s.gsub('-', '_').to_sym
|
|
14
20
|
end
|
|
15
21
|
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'chef-dk/policyfile_services/export_repo'
|
|
3
|
+
require 'chef-dk/policyfile_services/install'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
raise ChefSpec::Error::GemLoadError.new(gem: 'chef-dk', name: 'ChefDK')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
module ChefSpec
|
|
9
|
+
class Policyfile
|
|
10
|
+
class << self
|
|
11
|
+
extend Forwardable
|
|
12
|
+
def_delegators :instance, :setup!, :teardown!
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
include Singleton
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
@tmpdir = Dir.mktmpdir
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Setup and install the necessary dependencies in the temporary directory
|
|
23
|
+
#
|
|
24
|
+
def setup!
|
|
25
|
+
policyfile_path = File.join(Dir.pwd, 'Policyfile.rb')
|
|
26
|
+
|
|
27
|
+
installer = ChefDK::PolicyfileServices::Install.new(
|
|
28
|
+
policyfile: policyfile_path,
|
|
29
|
+
ui: ChefDK::UI.null
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
installer.run
|
|
33
|
+
|
|
34
|
+
exporter = ChefDK::PolicyfileServices::ExportRepo.new(
|
|
35
|
+
policyfile: policyfile_path,
|
|
36
|
+
export_dir: @tmpdir
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
FileUtils.rm_rf(@tmpdir)
|
|
40
|
+
exporter.run
|
|
41
|
+
|
|
42
|
+
::RSpec.configure do |config|
|
|
43
|
+
config.cookbook_path = [
|
|
44
|
+
File.join(@tmpdir, 'cookbooks'),
|
|
45
|
+
File.join(@tmpdir, 'cookbook_artifacts')
|
|
46
|
+
]
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#
|
|
51
|
+
# Remove the temporary directory
|
|
52
|
+
#
|
|
53
|
+
def teardown!
|
|
54
|
+
FileUtils.rm_rf(@tmpdir) if File.exist?(@tmpdir)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
RSpec.configure do |config|
|
|
60
|
+
config.before(:suite) { ChefSpec::Policyfile.setup! }
|
|
61
|
+
config.after(:suite) { ChefSpec::Policyfile.teardown! }
|
|
62
|
+
end
|
data/lib/chefspec/renderer.rb
CHANGED
|
@@ -68,12 +68,10 @@ module ChefSpec
|
|
|
68
68
|
template_context = Chef::Mixin::Template::TemplateContext.new([])
|
|
69
69
|
template_context.update({
|
|
70
70
|
:node => chef_run.node,
|
|
71
|
-
:template_finder => template_finder(chef_run,
|
|
71
|
+
:template_finder => template_finder(chef_run, cookbook_name),
|
|
72
72
|
}.merge(template.variables))
|
|
73
73
|
if template.respond_to?(:helper_modules) # Chef 11.4+
|
|
74
|
-
template.helper_modules
|
|
75
|
-
template_context.extend(helper_module)
|
|
76
|
-
end
|
|
74
|
+
template_context._extend_modules(template.helper_modules)
|
|
77
75
|
end
|
|
78
76
|
template_context.render_template(template_location)
|
|
79
77
|
else
|
data/lib/chefspec/rspec.rb
CHANGED
|
@@ -9,9 +9,12 @@ RSpec.configure do |config|
|
|
|
9
9
|
ChefSpec::Stubs::SearchRegistry.reset!
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
+
config.add_setting :berkshelf_options, default: {}
|
|
13
|
+
config.add_setting :file_cache_path
|
|
12
14
|
config.add_setting :cookbook_path
|
|
13
15
|
config.add_setting :role_path
|
|
14
16
|
config.add_setting :environment_path
|
|
17
|
+
config.add_setting :file_cache_path
|
|
15
18
|
config.add_setting :log_level, default: :warn
|
|
16
19
|
config.add_setting :path
|
|
17
20
|
config.add_setting :platform
|
|
@@ -2,6 +2,7 @@ require 'chef_zero/server'
|
|
|
2
2
|
require 'chef/cookbook_loader'
|
|
3
3
|
require 'chef/cookbook_uploader'
|
|
4
4
|
|
|
5
|
+
require_relative 'file_cache_path_proxy'
|
|
5
6
|
require_relative 'server_methods'
|
|
6
7
|
require_relative 'solo_runner'
|
|
7
8
|
|
|
@@ -11,6 +12,13 @@ module ChefSpec
|
|
|
11
12
|
|
|
12
13
|
# @see (SoloRunner#initialize)
|
|
13
14
|
def initialize(options = {})
|
|
15
|
+
# Unlike the SoloRunner, the file_cache_path needs to remain consistent
|
|
16
|
+
# for every Chef run or else the Chef client tries to loads the same
|
|
17
|
+
# cookbook multiple times and will encounter deprecated logic when
|
|
18
|
+
# creating LWRPs. It also slows down the entire process.
|
|
19
|
+
options[:file_cache_path] ||= RSpec.configuration.file_cache_path ||
|
|
20
|
+
ChefSpec::FileCachePathProxy.instance.file_cache_path
|
|
21
|
+
|
|
14
22
|
# Call super, but do not pass in the block because we want to customize
|
|
15
23
|
# our yielding.
|
|
16
24
|
super(options, &nil)
|
|
@@ -19,6 +27,7 @@ module ChefSpec
|
|
|
19
27
|
Chef::Config[:client_name] = 'chefspec'
|
|
20
28
|
Chef::Config[:node_name] = 'chefspec'
|
|
21
29
|
Chef::Config[:solo] = false
|
|
30
|
+
Chef::Config[:solo_legacy_mode] = false
|
|
22
31
|
|
|
23
32
|
Chef::Config[:chef_server_url] = server.url
|
|
24
33
|
Chef::Config[:http_retry_count] = 0
|
data/lib/chefspec/solo_runner.rb
CHANGED
|
@@ -79,6 +79,7 @@ module ChefSpec
|
|
|
79
79
|
Chef::Config[:role_path] = Array(@options[:role_path])
|
|
80
80
|
Chef::Config[:force_logger] = true
|
|
81
81
|
Chef::Config[:solo] = true
|
|
82
|
+
Chef::Config[:solo_legacy_mode] = true
|
|
82
83
|
Chef::Config[:environment_path] = @options[:environment_path]
|
|
83
84
|
|
|
84
85
|
yield node if block_given?
|
|
@@ -111,14 +112,22 @@ module ChefSpec
|
|
|
111
112
|
# Expand the run_list
|
|
112
113
|
expand_run_list!
|
|
113
114
|
|
|
114
|
-
# Setup the run_context
|
|
115
|
-
|
|
115
|
+
# Setup the run_context, rescuing the exception that happens when a
|
|
116
|
+
# resource is not defined on a particular platform
|
|
117
|
+
begin
|
|
118
|
+
@run_context = client.setup_run_context
|
|
119
|
+
rescue Chef::Exceptions::NoSuchResourceType => e
|
|
120
|
+
raise Error::MayNeedToSpecifyPlatform.new(original_error: e.message)
|
|
121
|
+
end
|
|
116
122
|
|
|
117
123
|
# Allow stubbing/mocking after the cookbook has been compiled but before the converge
|
|
118
124
|
yield if block_given?
|
|
119
125
|
|
|
120
126
|
@converging = true
|
|
121
|
-
@client.converge(@run_context)
|
|
127
|
+
converge_val = @client.converge(@run_context)
|
|
128
|
+
if converge_val.is_a?(Exception)
|
|
129
|
+
raise converge_val
|
|
130
|
+
end
|
|
122
131
|
self
|
|
123
132
|
end
|
|
124
133
|
|
|
@@ -299,6 +308,7 @@ module ChefSpec
|
|
|
299
308
|
cookbook_path: config.cookbook_path || calling_cookbook_path(caller),
|
|
300
309
|
role_path: config.role_path || default_role_path,
|
|
301
310
|
environment_path: config.environment_path || default_environment_path,
|
|
311
|
+
file_cache_path: config.file_cache_path,
|
|
302
312
|
log_level: config.log_level,
|
|
303
313
|
path: config.path,
|
|
304
314
|
platform: config.platform,
|
data/lib/chefspec/version.rb
CHANGED
data/lib/chefspec.rb
CHANGED
|
@@ -42,13 +42,13 @@ module ChefSpec
|
|
|
42
42
|
module_function :matchers
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
require_relative 'chefspec/extensions/chef/securable'
|
|
45
46
|
require_relative 'chefspec/extensions/chef/client'
|
|
46
47
|
require_relative 'chefspec/extensions/chef/conditional'
|
|
47
48
|
require_relative 'chefspec/extensions/chef/cookbook_uploader'
|
|
48
49
|
require_relative 'chefspec/extensions/chef/data_query'
|
|
49
50
|
require_relative 'chefspec/extensions/chef/lwrp_base'
|
|
50
51
|
require_relative 'chefspec/extensions/chef/resource'
|
|
51
|
-
require_relative 'chefspec/extensions/chef/securable'
|
|
52
52
|
require_relative 'chefspec/extensions/chef/resource/freebsd_package'
|
|
53
53
|
|
|
54
54
|
require_relative 'chefspec/mixins/normalize'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# Note: These specs don't use Berkshelf code directly as this project doesn't
|
|
4
|
+
# have a direct dependency on Berkshelf and loading it would impact the
|
|
5
|
+
# perfance of these specs. While not ideal, the test doubles provide enough of
|
|
6
|
+
# a standin for Berkshelf to exercise the `#matches?` behavior.
|
|
7
|
+
describe ChefSpec::Coverage::BerkshelfFilter do
|
|
8
|
+
let(:dependencies) do
|
|
9
|
+
[double('Berkshelf::Dependency', metadata?: true, name: "cookbookery")]
|
|
10
|
+
end
|
|
11
|
+
let(:berksfile) { double('Berkshelf::Berksfile', dependencies: dependencies) }
|
|
12
|
+
let(:resource) { Chef::Resource.new('theone') }
|
|
13
|
+
subject { described_class.new(berksfile) }
|
|
14
|
+
|
|
15
|
+
describe '#matches?' do
|
|
16
|
+
it 'returns truthy if resource source_line is nil' do
|
|
17
|
+
expect(subject.matches?(resource)).to be_truthy
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'when resource#source_line is under target cookbook' do
|
|
21
|
+
it 'normal unix path returns truthy' do
|
|
22
|
+
resource.source_line =
|
|
23
|
+
'/path/to/cookbooks/nope/recipes/default.rb:22'
|
|
24
|
+
expect(subject.matches?(resource)).to be_truthy
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'normal windows path returns truthy' do
|
|
28
|
+
resource.source_line =
|
|
29
|
+
'C:\\path\\to\\cookbooks\\nope\\recipes\\default.rb:22'
|
|
30
|
+
expect(subject.matches?(resource)).to be_truthy
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'mixed windows path returns truthy' do
|
|
34
|
+
resource.source_line =
|
|
35
|
+
'C:\\path\\to\\cookbooks/nope/recipes/default.rb:22'
|
|
36
|
+
expect(subject.matches?(resource)).to be_truthy
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context 'when resource#source_line is not under target cookbook' do
|
|
41
|
+
it 'normal unix path returns falsey' do
|
|
42
|
+
resource.source_line =
|
|
43
|
+
'/path/to/cookbooks/cookbookery/recipes/default.rb:22'
|
|
44
|
+
expect(subject.matches?(resource)).to be_falsey
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'normal windows path returns falsey' do
|
|
48
|
+
resource.source_line =
|
|
49
|
+
'C:\\path\\to\\cookbooks\\cookbookery\\recipes\\default.rb:22'
|
|
50
|
+
expect(subject.matches?(resource)).to be_falsey
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'mixed windows path returns falsey' do
|
|
54
|
+
resource.source_line =
|
|
55
|
+
'C:\\path\\to\\cookbooks/cookbookery/recipes/default.rb:22'
|
|
56
|
+
expect(subject.matches?(resource)).to be_falsey
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -65,7 +65,9 @@ describe ChefSpec::Server do
|
|
|
65
65
|
" a global Chef Server instance. Please use a ChefSpec::ServerRunner" \
|
|
66
66
|
" instead. More documentation can be found in the ChefSpec README."
|
|
67
67
|
)
|
|
68
|
-
expect{
|
|
68
|
+
expect {
|
|
69
|
+
ChefSpec::Server.any_method
|
|
70
|
+
}.to raise_error(ChefSpec::Error::NoConversionError)
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
it 'raises non-conversion error for any method called' do
|
data/spec/unit/macros_spec.rb
CHANGED
|
@@ -76,7 +76,7 @@ describe ChefSpec::Macros do
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
it 'sets the automatic attributes from a JSON data path' do
|
|
79
|
-
allow(File).to receive(:
|
|
79
|
+
allow(File).to receive(:exist?).with('/path/to/json').and_return(true)
|
|
80
80
|
allow(File).to receive(:read).with('/path/to/json').and_return('{ "ipaddress": "1.2.3.4" }')
|
|
81
81
|
node = described_class.stub_node('node.example', path: '/path/to/json')
|
|
82
82
|
expect(node['ipaddress']).to eq('1.2.3.4')
|
|
@@ -6,6 +6,17 @@ describe ChefSpec::Matchers::RenderFileMatcher do
|
|
|
6
6
|
let(:chef_run) { double('chef run', find_resource: file) }
|
|
7
7
|
subject { described_class.new(path) }
|
|
8
8
|
|
|
9
|
+
describe '#with_content' do
|
|
10
|
+
it 'accepts do/end syntax' do
|
|
11
|
+
subject.matches?(chef_run)
|
|
12
|
+
expect(
|
|
13
|
+
subject.with_content do |content|
|
|
14
|
+
'Does not raise ArgumentError'
|
|
15
|
+
end.expected_content.call
|
|
16
|
+
).to eq('Does not raise ArgumentError')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
9
20
|
describe '#failure_message' do
|
|
10
21
|
it 'has the right value' do
|
|
11
22
|
subject.matches?(chef_run)
|
data/spec/unit/renderer_spec.rb
CHANGED
|
@@ -9,8 +9,8 @@ describe ChefSpec::Renderer do
|
|
|
9
9
|
end
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
let(:chef_run) { double('chef_run') }
|
|
13
|
-
let(:resource) { double('resource') }
|
|
12
|
+
let(:chef_run) { double('chef_run', {node: 'node'}) }
|
|
13
|
+
let(:resource) { double('resource', {cookbook: 'cookbook', source: 'source', variables: {}}) }
|
|
14
14
|
subject { described_class.new(chef_run, resource) }
|
|
15
15
|
|
|
16
16
|
describe '#content' do
|
|
@@ -48,4 +48,22 @@ describe ChefSpec::Renderer do
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
|
+
|
|
52
|
+
describe 'content_from_template' do
|
|
53
|
+
it 'renders the template by extending modules for rendering paritals within the template' do
|
|
54
|
+
cookbook_collection = {}
|
|
55
|
+
cookbook_collection['cookbook'] = double('', {preferred_filename_on_disk_location: "/template/location"} )
|
|
56
|
+
allow(subject).to receive(:cookbook_collection).with('node').and_return(cookbook_collection)
|
|
57
|
+
allow(subject).to receive(:template_finder)
|
|
58
|
+
|
|
59
|
+
allow(resource).to receive(:helper_modules).and_return([Module.new])
|
|
60
|
+
allow(resource).to receive(:resource_name).and_return('template')
|
|
61
|
+
|
|
62
|
+
chef_template_context = double('context', {render_template: 'rendered template content',update: nil})
|
|
63
|
+
allow(Chef::Mixin::Template::TemplateContext).to receive(:new).and_return(chef_template_context)
|
|
64
|
+
|
|
65
|
+
expect(chef_template_context).to receive(:_extend_modules).with(resource.helper_modules)
|
|
66
|
+
expect(subject.content).to eq('rendered template content')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
51
69
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ChefSpec::ServerRunner do
|
|
4
|
+
context 'when the RSpec config is set' do
|
|
5
|
+
it 'does not create a tmpdir' do
|
|
6
|
+
allow(RSpec.configuration).to receive(:file_cache_path)
|
|
7
|
+
.and_return("/foo/bar")
|
|
8
|
+
expect(ChefSpec::FileCachePathProxy).to_not receive(:instance)
|
|
9
|
+
described_class.new
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
context 'when the RSpec config is not set' do
|
|
14
|
+
it 'creates and returns a tmpdir' do
|
|
15
|
+
expect(ChefSpec::FileCachePathProxy).to receive(:instance)
|
|
16
|
+
.and_call_original
|
|
17
|
+
described_class.new
|
|
18
|
+
expect(Chef::Config[:file_cache_path]).to match(/chefspec/)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'uses the same path' do
|
|
22
|
+
val = ChefSpec::FileCachePathProxy.instance.file_cache_path
|
|
23
|
+
expect(described_class.new.options[:file_cache_path]).to eq(val)
|
|
24
|
+
expect(described_class.new.options[:file_cache_path]).to eq(val)
|
|
25
|
+
expect(described_class.new.options[:file_cache_path]).to eq(val)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -97,7 +97,7 @@ describe ChefSpec::SoloRunner do
|
|
|
97
97
|
it 'sets the attributes from fauxhai' do
|
|
98
98
|
expect(hash['os']).to eq('linux')
|
|
99
99
|
expect(hash['languages']['ruby']['ruby_bin']).to eq('/usr/local/bin/ruby')
|
|
100
|
-
expect(hash['os_version']).to eq('3.2.0-
|
|
100
|
+
expect(hash['os_version']).to eq('3.2.0-92-generic')
|
|
101
101
|
expect(hash['fqdn']).to eq('fauxhai.local')
|
|
102
102
|
expect(hash['domain']).to eq('local')
|
|
103
103
|
expect(hash['ipaddress']).to eq('10.0.0.2')
|
|
@@ -110,6 +110,7 @@ describe ChefSpec::SoloRunner do
|
|
|
110
110
|
before do
|
|
111
111
|
allow(RSpec.configuration).to receive(:cookbook_path).and_return('./path')
|
|
112
112
|
allow(RSpec.configuration).to receive(:environment_path).and_return('./env-path')
|
|
113
|
+
allow(RSpec.configuration).to receive(:file_cache_path).and_return('./file-cache-path')
|
|
113
114
|
allow(RSpec.configuration).to receive(:log_level).and_return(:fatal)
|
|
114
115
|
allow(RSpec.configuration).to receive(:path).and_return('ohai.json')
|
|
115
116
|
allow(RSpec.configuration).to receive(:platform).and_return('ubuntu')
|
|
@@ -120,6 +121,7 @@ describe ChefSpec::SoloRunner do
|
|
|
120
121
|
options = described_class.new.options
|
|
121
122
|
expect(options[:cookbook_path]).to eq('./path')
|
|
122
123
|
expect(options[:environment_path]).to eq('./env-path')
|
|
124
|
+
expect(options[:file_cache_path]).to eq('./file-cache-path')
|
|
123
125
|
expect(options[:log_level]).to eq(:fatal)
|
|
124
126
|
expect(options[:path]).to eq('ohai.json')
|
|
125
127
|
expect(options[:platform]).to eq('ubuntu')
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
It appears that Chef could not find the resource on the given platform. As of
|
|
2
|
+
Chef 12.4, Chef conditionally loads resources based on the operating system
|
|
3
|
+
being provisioned. Double-check the error below and ensure you did not make any
|
|
4
|
+
typographical errors, and then continue reading.
|
|
5
|
+
|
|
6
|
+
The default operating system for ChefSpec is "chefspec", which means Chef will
|
|
7
|
+
not load many resources by default. For example, "dpkg_package" is not a
|
|
8
|
+
resource that is available on the "chefspec" operating system just like
|
|
9
|
+
"freebsd_package" is not available on the Windows operating system. As such,
|
|
10
|
+
you may get a Chef::Exceptions::NoSuchResourceType when using ChefSpec's default
|
|
11
|
+
options.
|
|
12
|
+
|
|
13
|
+
You can specify the platform and version you would like ChefSpec to act like
|
|
14
|
+
by specifying the platform and version like so:
|
|
15
|
+
|
|
16
|
+
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04')
|
|
17
|
+
|
|
18
|
+
You can read more information in ChefSpec's README or the Fauxhai project:
|
|
19
|
+
|
|
20
|
+
https://github.com/sethvargo/chefspec#configuration
|
|
21
|
+
https://github.com/customink/fauxhai
|
|
22
|
+
|
|
23
|
+
Here is the original error:
|
|
24
|
+
|
|
25
|
+
<%= @original_error %>
|