/
spec_helper.rb
90 lines (67 loc) · 2.43 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true
require 'pathname'
ROOT_DIR = Pathname.new(File.expand_path('..', __dir__)) unless defined?(ROOT_DIR)
ENV['RACK_ENV'] = 'test'
require 'bundler/setup'
require 'simplecov'
# Configure SimpleCov
SimpleCov.start do
track_files 'lib/**/*.rb'
add_filter 'spec'
end
require 'open3'
require 'thor'
require 'fileutils'
require 'timecop'
require_relative '../lib/facter/resolvers/base_resolver'
Dir[ROOT_DIR.join('spec/mocks/*.rb')].sort.each { |file| require file }
require_relative 'custom_facts/puppetlabs_spec/files'
require 'facter'
require 'facter/framework/cli/cli'
require 'facter/framework/cli/cli_launcher'
Dir.glob(File.join('./lib/facter/util', '/**/*/', '*.rb'), &method(:require))
Dir.glob(File.join('./lib/facter/facts', '/**/*/', '*.rb'), &method(:require))
Dir.glob(File.join('./lib/facter/resolvers', '/**/*/', '*.rb'), &method(:require))
default_coverage = 90
SimpleCov.minimum_coverage ENV['COVERAGE'] || default_coverage
def colorize(str, color)
"#{color}#{str}#{Facter::RESET}"
end
# Configure webmock
require 'webmock/rspec'
WebMock.disable_net_connect!
# Configure RSpec
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expose_dsl_globally = true
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.mock_with :rspec do |mocks|
# This option should be set when all dependencies are being loaded
# before a spec run, as is the case in a typical spec helper. It will
# cause any verifying double instantiation for a class that does not
# exist to raise, protecting against incorrectly spelt names.
mocks.verify_doubled_constant_names = true
# This option forces the same argument and method existence checks that are
# performed for object_double are also performed on partial doubles.
# You should set this unless you have a good reason not to.
# It defaults to off only for backwards compatibility.
mocks.verify_partial_doubles = true
end
config.before do
LegacyFacter.clear
LegacyFacter.clear_messages
end
config.after do
Facter::OptionStore.reset
end
# This will cleanup any files that were created with tmpdir or tmpfile
config.extend PuppetlabsSpec::Files
config.after do
PuppetlabsSpec::Files.cleanup
end
end