-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_helper.rb
62 lines (53 loc) · 1.89 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Encoding: UTF-8
require 'chef'
require 'chefspec'
require 'json'
require 'tempfile'
require 'simplecov'
require 'simplecov-console'
require 'coveralls'
require 'tmpdir'
require 'fileutils'
require_relative 'support/matchers/private_internet_access'
require_relative 'support/resource/dmg_package'
require_relative 'support/provider/dmg_package'
require_relative 'support/provider/windows_cookbook_package'
RSpec.configure do |c|
c.color = true
c.before(:suite) do
COOKBOOK_PATH = Dir.mktmpdir('chefspec')
metadata = Chef::Cookbook::Metadata.new
metadata.from_file(File.expand_path('../../metadata.rb', __FILE__))
link_path = File.join(COOKBOOK_PATH, metadata.name)
FileUtils.ln_s(File.expand_path('../..', __FILE__), link_path)
c.cookbook_path = COOKBOOK_PATH
end
c.before(:each) do
# Don't worry about external cookbook dependencies
allow_any_instance_of(Chef::Cookbook::Metadata).to receive(:depends)
# Prep lookup() for the stubs below
allow_any_instance_of(Chef::ResourceCollection).to receive(:lookup)
.and_call_original
# Test each recipe in isolation, regardless of includes
@included_recipes = []
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?)
.and_return(false)
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe) do |_, i|
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipe?)
.with(i)
.and_return(true)
@included_recipes << i
end
allow_any_instance_of(Chef::RunContext).to receive(:loaded_recipes)
.and_return(@included_recipes)
end
c.after(:suite) { FileUtils.rm_r(COOKBOOK_PATH) }
end
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
Coveralls::SimpleCov::Formatter,
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console
]
SimpleCov.minimum_coverage 90
SimpleCov.start
at_exit { ChefSpec::Coverage.report! }