|
3 | 3 | # Chef::Mixin::ShellOut is required to mock shellout |
4 | 4 | include Chef::Mixin::ShellOut |
5 | 5 |
|
| 6 | +# Global monkey patch for ChefSpec::SoloRunner to include cookbook paths |
| 7 | +ChefSpec::SoloRunner.class_eval do |
| 8 | + alias_method :solo_original_initialize, :initialize |
| 9 | + |
| 10 | + def initialize(options = {}) |
| 11 | + options ||= {} |
| 12 | + options[:cookbook_path] ||= [ |
| 13 | + File.expand_path('../..', __dir__), |
| 14 | + File.expand_path('../../cookbooks', __dir__), |
| 15 | + File.expand_path('../../cookbooks/third-party', __dir__) |
| 16 | + ] |
| 17 | + solo_original_initialize(options) |
| 18 | + end |
| 19 | +end |
| 20 | + |
| 21 | +# Patch other runners if they exist |
| 22 | +if defined?(ChefSpec::ServerRunner) |
| 23 | + ChefSpec::ServerRunner.class_eval do |
| 24 | + alias_method :server_original_initialize, :initialize |
| 25 | + |
| 26 | + def initialize(options = {}) |
| 27 | + options ||= {} |
| 28 | + options[:cookbook_path] ||= [ |
| 29 | + File.expand_path('../..', __dir__), |
| 30 | + File.expand_path('../../cookbooks', __dir__), |
| 31 | + File.expand_path('../../cookbooks/third-party', __dir__) |
| 32 | + ] |
| 33 | + server_original_initialize(options) |
| 34 | + end |
| 35 | + end |
| 36 | +end |
| 37 | + |
6 | 38 | RSpec.configure do |c| |
| 39 | + c.cookbook_path = [ |
| 40 | + File.expand_path('../..', __dir__), |
| 41 | + File.expand_path('../../cookbooks', __dir__), |
| 42 | + File.expand_path('../../cookbooks/third-party', __dir__) |
| 43 | + ] |
7 | 44 | c.before(:each) do |
8 | 45 | allow(File).to receive(:exist?).and_call_original |
9 | 46 | allow(Dir).to receive(:exist?).and_call_original |
@@ -58,7 +95,16 @@ def for_all_node_types |
58 | 95 | end |
59 | 96 |
|
60 | 97 | def runner(platform:, version:, step_into: []) |
61 | | - ChefSpec::SoloRunner.new(platform: platform, version: version, step_into: step_into) do |node| |
| 98 | + ChefSpec::SoloRunner.new( |
| 99 | + platform: platform, |
| 100 | + version: version, |
| 101 | + step_into: step_into, |
| 102 | + cookbook_path: [ |
| 103 | + File.expand_path('../..', __dir__), |
| 104 | + File.expand_path('../../cookbooks', __dir__), |
| 105 | + File.expand_path('../../cookbooks/third-party', __dir__) |
| 106 | + ] |
| 107 | + ) do |node| |
62 | 108 | yield node if block_given? |
63 | 109 | end |
64 | 110 | end |
|
0 commit comments