diff options
Diffstat (limited to 'spec/unit/formatters')
5 files changed, 43 insertions, 43 deletions
diff --git a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb index 95911689e4..ac19e91922 100644 --- a/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb @@ -51,7 +51,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do # Error inspector originally used file_cache_path which is incorrect on # chef-solo. Using cookbook_path should do the right thing for client and # solo. - Chef::Config.stub(:cookbook_path).and_return([ "/home/someuser/dev-laptop/cookbooks" ]) + allow(Chef::Config).to receive(:cookbook_path).and_return([ "/home/someuser/dev-laptop/cookbooks" ]) @trace = [ "/home/someuser/dev-laptop/cookbooks/syntax-err/recipes/default.rb:14:in `from_file'", "/home/someuser/dev-laptop/cookbooks/syntax-err/recipes/default.rb:11:in `from_file'", @@ -65,15 +65,15 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do "/home/someuser/dev-laptop/cookbooks/syntax-err/recipes/default.rb:14:in `from_file'", "/home/someuser/dev-laptop/cookbooks/syntax-err/recipes/default.rb:11:in `from_file'", ] - @inspector.filtered_bt.should == @expected_filtered_trace + expect(@inspector.filtered_bt).to eq(@expected_filtered_trace) end end describe "when explaining an error in the compile phase" do before do - Chef::Config.stub(:cookbook_path).and_return([ "/var/chef/cache/cookbooks" ]) + allow(Chef::Config).to receive(:cookbook_path).and_return([ "/var/chef/cache/cookbooks" ]) recipe_lines = BAD_RECIPE.split("\n").map {|l| l << "\n" } - IO.should_receive(:readlines).with("/var/chef/cache/cookbooks/syntax-err/recipes/default.rb").and_return(recipe_lines) + expect(IO).to receive(:readlines).with("/var/chef/cache/cookbooks/syntax-err/recipes/default.rb").and_return(recipe_lines) @trace = [ "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:14:in `from_file'", "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:11:in `from_file'", @@ -86,7 +86,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do end it "finds the line number of the error from the stacktrace" do - @inspector.culprit_line.should == 14 + expect(@inspector.culprit_line).to eq(14) end it "prints a pretty message" do @@ -96,9 +96,9 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do describe "when explaining an error on windows" do before do - Chef::Config.stub(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) + allow(Chef::Config).to receive(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) recipe_lines = BAD_RECIPE.split("\n").map {|l| l << "\n" } - IO.should_receive(:readlines).at_least(1).times.with(/:\/opscode\/chef\/var\/cache\/cookbooks\/foo\/recipes\/default.rb/).and_return(recipe_lines) + expect(IO).to receive(:readlines).at_least(1).times.with(/:\/opscode\/chef\/var\/cache\/cookbooks\/foo\/recipes\/default.rb/).and_return(recipe_lines) @trace = [ "C:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb:14 in `from_file'", "C:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.14.0/lib/chef/run_context.rb:144:in `rescue in block in load_libraries'", @@ -131,7 +131,7 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do describe "and examining the stack trace for a recipe" do it "find the culprit recipe name when the drive letter is upper case" do - @inspector.culprit_file.should == "C:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb" + expect(@inspector.culprit_file).to eq("C:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb") end it "find the culprit recipe name when the drive letter is lower case" do @@ -139,12 +139,12 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do @exception.set_backtrace(@trace) @inspector = described_class.new(@path, @exception) @inspector.add_explanation(@description) - @inspector.culprit_file.should == "c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb" + expect(@inspector.culprit_file).to eq("c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb") end end it "finds the line number of the error from the stack trace" do - @inspector.culprit_line.should == 14 + expect(@inspector.culprit_line).to eq(14) end it "prints a pretty message" do @@ -154,9 +154,9 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do describe "when explaining an error on windows, and the backtrace lowercases the drive letter" do before do - Chef::Config.stub(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) + allow(Chef::Config).to receive(:cookbook_path).and_return([ "C:/opscode/chef/var/cache/cookbooks" ]) recipe_lines = BAD_RECIPE.split("\n").map {|l| l << "\n" } - IO.should_receive(:readlines).with("c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb").and_return(recipe_lines) + expect(IO).to receive(:readlines).with("c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb").and_return(recipe_lines) @trace = [ "c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb:14 in `from_file'", "c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.14.0/lib/chef/run_context.rb:144:in `rescue in block in load_libraries'", @@ -187,11 +187,11 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do end it "finds the culprit recipe name from the stacktrace" do - @inspector.culprit_file.should == "c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb" + expect(@inspector.culprit_file).to eq("c:/opscode/chef/var/cache/cookbooks/foo/recipes/default.rb") end it "finds the line number of the error from the stack trace" do - @inspector.culprit_line.should == 14 + expect(@inspector.culprit_line).to eq(14) end it "prints a pretty message" do diff --git a/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb index 06d45472e4..7e4d89f144 100644 --- a/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb @@ -34,7 +34,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = %Q({"error": [{"message": "gtfo"}]) @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") - @response.stub(:body).and_return(@response_body) + allow(@response).to receive(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) forbidden", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @@ -42,7 +42,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do end it "prints a nice message" do - lambda { @description.display(@outputter) }.should_not raise_error + expect { @description.display(@outputter) }.not_to raise_error end end @@ -55,7 +55,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[\"{\\\"non_existent_cookbooks\\\":[\\\"apache2\\\"],\\\"cookbooks_with_no_versions\\\":[\\\"users\\\"],\\\"message\\\":\\\"Run list contains invalid items: no such cookbook nope.\\\"}\"]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") - @response.stub(:body).and_return(@response_body) + allow(@response).to receive(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @@ -66,9 +66,9 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @description.display(@outputter) @outputter_output.rewind observed_output = @outputter_output.read - observed_output.should include("apache2") - observed_output.should include("users") - observed_output.should_not include("Run list contains invalid items: no such cookbook nope.") + expect(observed_output).to include("apache2") + expect(observed_output).to include("users") + expect(observed_output).not_to include("Run list contains invalid items: no such cookbook nope.") end end @@ -83,7 +83,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[{\"non_existent_cookbooks\":[],\"cookbooks_with_no_versions\":[],\"message\":\"unable to solve dependencies in alotted time.\"}]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") - @response.stub(:body).and_return(@response_body) + allow(@response).to receive(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @@ -93,7 +93,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do it "prints a pretty message" do @description.display(@outputter) @outputter_output.rewind - @outputter_output.read.should include("unable to solve dependencies in alotted time.") + expect(@outputter_output.read).to include("unable to solve dependencies in alotted time.") end end @@ -106,7 +106,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @response_body = "{\"error\":[{\"non_existent_cookbooks\":[\"apache2\"],\"cookbooks_with_no_versions\":[\"users\"],\"message\":\"Run list contains invalid items: no such cookbook nope.\"}]}" @response = Net::HTTPPreconditionFailed.new("1.1", "412", "(response) unauthorized") - @response.stub(:body).and_return(@response_body) + allow(@response).to receive(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) precondition failed", @response) @inspector = Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector.new(@expanded_run_list, @exception) @@ -117,9 +117,9 @@ describe Chef::Formatters::ErrorInspectors::CookbookResolveErrorInspector do @description.display(@outputter) @outputter_output.rewind observed_output = @outputter_output.read - observed_output.should include("apache2") - observed_output.should include("users") - observed_output.should_not include("Run list contains invalid items: no such cookbook nope.") + expect(observed_output).to include("apache2") + expect(observed_output).to include("users") + expect(observed_output).not_to include("Run list contains invalid items: no such cookbook nope.") end end diff --git a/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb index 87c3708ef1..775a1838f3 100644 --- a/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb @@ -29,7 +29,7 @@ describe Chef::Formatters::ErrorInspectors::CookbookSyncErrorInspector do before do @response_body = "sad trombone orchestra" @response = Net::HTTPBadGateway.new("1.1", "502", "(response) bad gateway") - @response.stub(:body).and_return(@response_body) + allow(@response).to receive(:body).and_return(@response_body) @exception = Net::HTTPFatalError.new("(exception) bad gateway", @response) @inspector = described_class.new({}, @exception) @inspector.add_explanation(@description) diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb index 6691553ddd..ee957ed450 100644 --- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb @@ -42,7 +42,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do @outputter = Chef::Formatters::IndentableOutputStream.new(@stdout, STDERR) #@outputter = Chef::Formatters::IndentableOutputStream.new(STDOUT, STDERR) - Chef::Config.stub(:cookbook_path).and_return([ "/var/chef/cache" ]) + allow(Chef::Config).to receive(:cookbook_path).and_return([ "/var/chef/cache" ]) end describe "when explaining an error converging a resource" do @@ -74,7 +74,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:11:in `from_file'", ] - @inspector.filtered_bt.should == @expected_filtered_trace + expect(@inspector.filtered_bt).to eq(@expected_filtered_trace) end it "prints a pretty message" do @@ -105,7 +105,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do it "includes contextual info from the template error in the output" do @description.display(@outputter) - @stdout.string.should include(@error.source_listing) + expect(@stdout.string).to include(@error.source_listing) end @@ -115,40 +115,40 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do before do # fake code to run through #recipe_snippet source_file = [ "if true", "var = non_existant", "end" ] - IO.stub(:readlines).and_return(source_file) - File.stub(:exists?).and_return(true) + allow(IO).to receive(:readlines).and_return(source_file) + allow(File).to receive(:exists?).and_return(true) end it "parses a Windows path" do source_line = "C:/Users/btm/chef/chef/spec/unit/fake_file.rb:2: undefined local variable or method `non_existant' for main:Object (NameError)" @resource.source_line = source_line @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - @inspector.recipe_snippet.should match(/^# In C:\/Users\/btm/) + expect(@inspector.recipe_snippet).to match(/^# In C:\/Users\/btm/) end it "parses a unix path" do source_line = "/home/btm/src/chef/chef/spec/unit/fake_file.rb:2: undefined local variable or method `non_existant' for main:Object (NameError)" @resource.source_line = source_line @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - @inspector.recipe_snippet.should match(/^# In \/home\/btm/) + expect(@inspector.recipe_snippet).to match(/^# In \/home\/btm/) end context "when the recipe file does not exist" do before do - File.stub(:exists?).and_return(false) - IO.stub(:readlines).and_raise(Errno::ENOENT) + allow(File).to receive(:exists?).and_return(false) + allow(IO).to receive(:readlines).and_raise(Errno::ENOENT) end it "does not try to parse a recipe in chef-shell/irb (CHEF-3411)" do @resource.source_line = "(irb#1):1:in `irb_binding'" @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - @inspector.recipe_snippet.should be_nil + expect(@inspector.recipe_snippet).to be_nil end it "does not raise an exception trying to load a non-existant file (CHEF-3411)" do @resource.source_line = "/somewhere/in/space" @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - lambda { @inspector.recipe_snippet }.should_not raise_error + expect { @inspector.recipe_snippet }.not_to raise_error end end end @@ -175,7 +175,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do end it "does not generate an error" do - lambda { @inspector.add_explanation(@description) }.should_not raise_error + expect { @inspector.add_explanation(@description) }.not_to raise_error @description.display(@outputter) end end diff --git a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb index 7f68c4fba4..1cd97596a7 100644 --- a/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb @@ -55,10 +55,10 @@ describe Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector do @response_body = "forbidden" @response = Net::HTTPForbidden.new("1.1", "403", "(response) forbidden") - @response.stub(:body).and_return(@response_body) + allow(@response).to receive(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) forbidden", @response) @inspector = Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector.new(@node, @exception) - @inspector.stub(:config).and_return(:node_name => "unit-test.example.com") + allow(@inspector).to receive(:config).and_return(:node_name => "unit-test.example.com") @inspector.add_explanation(@description) end @@ -73,11 +73,11 @@ describe Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector do before do @response_body = "check your key and node name" @response = Net::HTTPUnauthorized.new("1.1", "401", "(response) unauthorized") - @response.stub(:body).and_return(@response_body) + allow(@response).to receive(:body).and_return(@response_body) @exception = Net::HTTPServerException.new("(exception) unauthorized", @response) @inspector = Chef::Formatters::ErrorInspectors::RunListExpansionErrorInspector.new(@node, @exception) - @inspector.stub(:config).and_return(:node_name => "unit-test.example.com", + allow(@inspector).to receive(:config).and_return(:node_name => "unit-test.example.com", :client_key => "/etc/chef/client.pem", :chef_server_url => "http://chef.example.com") |