diff options
| author | Noah Kantrowitz <noah@coderanger.net> | 2016-09-06 16:21:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-06 16:21:45 -0700 |
| commit | 9eea32162370b9bf6d0a00f1b4fe7e14850f03d3 (patch) | |
| tree | b452efbb31779f28ba67594ae90ff30fe76123e4 /spec/unit | |
| parent | 977d1e6785ebb69e6b2975072965fe370124af4e (diff) | |
| parent | 073405c5fd6e73d286da4cce9fdd1c1ffa3e2dcd (diff) | |
| download | chef-9eea32162370b9bf6d0a00f1b4fe7e14850f03d3.tar.gz | |
Merge pull request #5281 from coderanger/recipe_file_loaded
Hook up the recipe_file_loaded event which was defined but not actually called
Diffstat (limited to 'spec/unit')
| -rw-r--r-- | spec/unit/event_dispatch/dispatcher_spec.rb | 4 | ||||
| -rw-r--r-- | spec/unit/run_context/cookbook_compiler_spec.rb | 44 |
2 files changed, 45 insertions, 3 deletions
diff --git a/spec/unit/event_dispatch/dispatcher_spec.rb b/spec/unit/event_dispatch/dispatcher_spec.rb index 2360b2675d..5061a9845f 100644 --- a/spec/unit/event_dispatch/dispatcher_spec.rb +++ b/spec/unit/event_dispatch/dispatcher_spec.rb @@ -52,8 +52,8 @@ describe Chef::EventDispatch::Dispatcher do dispatcher.synchronized_cookbook("apache2", cookbook_version) exception = StandardError.new("foo") - expect(event_sink).to receive(:recipe_file_load_failed).with("/path/to/file.rb", exception) - dispatcher.recipe_file_load_failed("/path/to/file.rb", exception) + expect(event_sink).to receive(:recipe_file_load_failed).with("/path/to/file.rb", exception, "myrecipe") + dispatcher.recipe_file_load_failed("/path/to/file.rb", exception, "myrecipe") end context "when an event sink has fewer arguments for an event" do diff --git a/spec/unit/run_context/cookbook_compiler_spec.rb b/spec/unit/run_context/cookbook_compiler_spec.rb index 868bed4bfd..feb39615b6 100644 --- a/spec/unit/run_context/cookbook_compiler_spec.rb +++ b/spec/unit/run_context/cookbook_compiler_spec.rb @@ -158,7 +158,49 @@ describe Chef::RunContext::CookbookCompiler do end describe "loading recipes" do - # Tests for this behavior are in RunContext's tests + # Additional tests for this behavior are in RunContext's tests + + describe "event dispatch" do + let(:recipe) { "dependency1::default" } + let(:recipe_path) do + File.expand_path("../../../data/run_context/cookbooks/dependency1/recipes/default.rb", __FILE__).tap do |path| + path.gsub!(File::SEPARATOR, File::ALT_SEPARATOR) if File::ALT_SEPARATOR + end + end + before do + node.run_list(recipe) + end + subject { compiler.compile_recipes } + + it "dispatches normally" do + allow(run_context).to receive(:load_recipe) + expect(events).to receive(:recipe_load_start).with(1) + expect(events).to receive(:recipe_file_loaded).with(recipe_path, "dependency1::default") + expect(events).to receive(:recipe_load_complete).with(no_args) + subject + end + + it "dispatches when a recipe is not found" do + exc = Chef::Exceptions::RecipeNotFound.new + allow(run_context).to receive(:load_recipe).and_raise(exc) + expect(events).to receive(:recipe_load_start).with(1) + expect(events).to_not receive(:recipe_file_loaded) + expect(events).to receive(:recipe_not_found).with(exc) + expect(events).to_not receive(:recipe_load_complete) + expect { subject }.to raise_error(exc) + end + + it "dispatches when a recipe has an error" do + exc = ArgumentError.new + allow(run_context).to receive(:load_recipe).and_raise(exc) + expect(events).to receive(:recipe_load_start).with(1) + expect(events).to_not receive(:recipe_file_loaded) + expect(events).to receive(:recipe_file_load_failed).with(recipe_path, exc, "dependency1::default") + expect(events).to_not receive(:recipe_load_complete) + expect { subject }.to raise_error(exc) + end + end + end describe "listing cookbook order" do |
