|
3 | 3 | # Chef::Mixin::ShellOut is required to mock shellout |
4 | 4 | include Chef::Mixin::ShellOut |
5 | 5 |
|
| 6 | +# Create symlinks for third-party cookbooks so ChefSpec can find them |
| 7 | +third_party_dir = File.expand_path('../../cookbooks/third-party', __dir__) |
| 8 | +cookbooks_dir = File.expand_path('../../cookbooks', __dir__) |
| 9 | + |
| 10 | +if Dir.exist?(third_party_dir) |
| 11 | + Dir.entries(third_party_dir).each do |entry| |
| 12 | + next if entry.start_with?('.') |
| 13 | + source = File.join(third_party_dir, entry) |
| 14 | + target = File.join(cookbooks_dir, entry) |
| 15 | + |
| 16 | + if Dir.exist?(source) && !File.exist?(target) |
| 17 | + File.symlink(source, target) |
| 18 | + end |
| 19 | + end |
| 20 | +end |
| 21 | + |
6 | 22 | RSpec.configure do |c| |
| 23 | + c.cookbook_path = [ |
| 24 | + File.expand_path('../..', __dir__), |
| 25 | + File.expand_path('../../cookbooks', __dir__), |
| 26 | + File.expand_path('../../cookbooks/third-party', __dir__) |
| 27 | + ] |
7 | 28 | c.before(:each) do |
8 | 29 | allow(File).to receive(:exist?).and_call_original |
9 | 30 | allow(Dir).to receive(:exist?).and_call_original |
@@ -58,7 +79,16 @@ def for_all_node_types |
58 | 79 | end |
59 | 80 |
|
60 | 81 | def runner(platform:, version:, step_into: []) |
61 | | - ChefSpec::SoloRunner.new(platform: platform, version: version, step_into: step_into) do |node| |
| 82 | + ChefSpec::SoloRunner.new( |
| 83 | + platform: platform, |
| 84 | + version: version, |
| 85 | + step_into: step_into, |
| 86 | + cookbook_path: [ |
| 87 | + File.expand_path('../..', __dir__), |
| 88 | + File.expand_path('../../cookbooks', __dir__), |
| 89 | + File.expand_path('../../cookbooks/third-party', __dir__) |
| 90 | + ] |
| 91 | + ) do |node| |
62 | 92 | yield node if block_given? |
63 | 93 | end |
64 | 94 | end |
|
0 commit comments