-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move spec_helper customizations to spec_helper_local and .sync.yml.
- Loading branch information
Showing
5 changed files
with
67 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Hash | ||
# deep_merge copied with minor adaptation from: | ||
# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/deep_mergeable.rb | ||
def deep_merge(other, &block) | ||
dup.deep_merge!(other, &block) | ||
end | ||
|
||
def deep_merge!(other, &block) | ||
merge!(other) do |key, this_val, other_val| | ||
if this_val.is_a?(Hash) && other_val.is_a?(Hash) | ||
this_val.deep_merge(other_val, &block) | ||
elsif block_given? | ||
block.call(key, this_val, other_val) | ||
else | ||
other_val | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Stub the default dependency loader to do normal resolution except where overridden | ||
def stub_loader! | ||
allow_any_instance_of(Puppet::Pops::Loader::DependencyLoader).to receive(:load).and_call_original | ||
end | ||
|
||
# Stub the dependency loader to resolve a named function to a double of some type | ||
# | ||
# @param name [String] The name of the puppet function to stub | ||
# @param dbl [RSpec double] Optional RSpec double with `call` mocked; | ||
# will be used instead of the block if supplied | ||
# @yield [*args] A block that takes all parameters given to the puppet function; | ||
# required if dbl is not supplied, and ignored if dbl is supplied | ||
def stub_function(name, dbl = nil, &func) | ||
func = dbl || func | ||
stub = ->(_scope, *args, &block) do | ||
func.call(*args, &block) | ||
end | ||
allow_any_instance_of(Puppet::Pops::Loader::DependencyLoader).to receive(:load).with(:function, name).and_return(stub) | ||
end | ||
|
||
def stub(name) | ||
dbl = double(name) | ||
|
||
yield dbl | ||
stub_function(name, dbl) | ||
end | ||
|
||
def allow_call(dbl) | ||
allow(dbl).to receive(:call) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'faker' | ||
require 'spec_helper/deep_merge' | ||
require 'spec_helper/stub_loader' |