summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-07-15 15:13:33 -0700
committerGitHub <noreply@github.com>2020-07-15 15:13:33 -0700
commit35bbf1262cf5cb0319be980b055a7f8faf335700 (patch)
treeaeb9f1a8fd038b81b35d44d5e96c03887e059937
parent58f3e9405c872df1f22886ed6ce4843c7f3d4c2d (diff)
parent35dba09fdbb12b479b366d0e6a5252566fa47af8 (diff)
downloadchef-35bbf1262cf5cb0319be980b055a7f8faf335700.tar.gz
Merge pull request #10153 from chef/raise-on-raise_error
Don't allow tests to set an expectation without specific error type
-rw-r--r--lib/chef/chef_fs/parallelizer/parallel_enumerable.rb2
-rw-r--r--spec/functional/resource/group_spec.rb8
-rw-r--r--spec/functional/resource/remote_file_spec.rb8
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/support/shared/unit/application_dot_d.rb1
-rw-r--r--spec/unit/chef_fs/parallelizer_spec.rb (renamed from spec/unit/chef_fs/parallelizer.rb)2
6 files changed, 10 insertions, 12 deletions
diff --git a/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb b/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb
index 08fbcd4a41..5fafc5c88f 100644
--- a/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb
+++ b/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb
@@ -145,7 +145,7 @@ class Chef
def each_with_exceptions_unordered
if @each_running
- raise "each() called on parallel enumerable twice simultaneously! Bad mojo"
+ raise "each() called on parallel enumerable twice simultaneously! Bad mojo"
end
@each_running = true
diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb
index 8fca689e68..7e5b0725c1 100644
--- a/spec/functional/resource/group_spec.rb
+++ b/spec/functional/resource/group_spec.rb
@@ -159,8 +159,10 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do
# excluded_members can only be used when append is set. It is ignored otherwise.
let(:excluded_members) { [] }
+ let(:expected_error_class) { windows? ? ArgumentError : Mixlib::ShellOut::ShellCommandFailed }
+
it "should raise an error" do
- expect { group_resource.run_action(tested_action) }.to raise_error
+ expect { group_resource.run_action(tested_action) }.to raise_error(expected_error_class)
end
end
@@ -169,8 +171,10 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do
group_resource.append(true)
end
+ let(:expected_error_class) { windows? ? Chef::Exceptions::Win32APIError : Mixlib::ShellOut::ShellCommandFailed }
+
it "should raise an error" do
- expect { group_resource.run_action(tested_action) }.to raise_error
+ expect { group_resource.run_action(tested_action) }.to raise_error(expected_error_class)
end
end
end
diff --git a/spec/functional/resource/remote_file_spec.rb b/spec/functional/resource/remote_file_spec.rb
index f4a3d5346d..09e4fdccb4 100644
--- a/spec/functional/resource/remote_file_spec.rb
+++ b/spec/functional/resource/remote_file_spec.rb
@@ -409,13 +409,7 @@ describe Chef::Resource::RemoteFile do
it "should not create the file" do
# This can legitimately raise either Errno::EADDRNOTAVAIL or Errno::ECONNREFUSED
# in different Ruby versions.
- old_value = RSpec::Expectations.configuration.on_potential_false_positives
- RSpec::Expectations.configuration.on_potential_false_positives = :nothing
- begin
- expect { resource.run_action(:create) }.to raise_error
- ensure
- RSpec::Expectations.configuration.on_potential_false_positives = old_value
- end
+ expect { resource.run_action(:create) }.to raise_error(SystemCallError)
expect(File).not_to exist(path)
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index fd74a191f1..18a2ae888b 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -116,6 +116,7 @@ RSpec.configure do |config|
config.include(MockShellout::RSpec)
config.filter_run focus: true
config.filter_run_excluding external: true
+ config.raise_on_warning = true
# Explicitly disable :should syntax
# And set max_formatted_output_length to nil to prevent RSpec from doing truncation.
diff --git a/spec/support/shared/unit/application_dot_d.rb b/spec/support/shared/unit/application_dot_d.rb
index 398ff74d8a..a1606b4ff3 100644
--- a/spec/support/shared/unit/application_dot_d.rb
+++ b/spec/support/shared/unit/application_dot_d.rb
@@ -41,7 +41,6 @@ shared_examples_for "an application that loads a dot d" do
expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_return("foo 0")
expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_return("bar 0")
expect(IO).to receive(:read).with(Pathname.new("#{client_d_dir}/02-strings.rb").cleanpath.to_s).and_return("strings 0")
- allow(app).to receive(:apply_config).with(anything, Chef::Config.platform_specific_path("/etc/chef/client.rb")).and_call_original.ordered
expect(app).to receive(:apply_config).with("foo 0", Pathname.new("#{client_d_dir}/00-foo.rb").cleanpath.to_s).and_call_original.ordered
expect(app).to receive(:apply_config).with("bar 0", Pathname.new("#{client_d_dir}/01-bar.rb").cleanpath.to_s).and_call_original.ordered
expect(app).to receive(:apply_config).with("strings 0", Pathname.new("#{client_d_dir}/02-strings.rb").cleanpath.to_s).and_call_original.ordered
diff --git a/spec/unit/chef_fs/parallelizer.rb b/spec/unit/chef_fs/parallelizer_spec.rb
index d43e48b7bc..3c675e74fe 100644
--- a/spec/unit/chef_fs/parallelizer.rb
+++ b/spec/unit/chef_fs/parallelizer_spec.rb
@@ -405,7 +405,7 @@ describe Chef::ChefFS::Parallelizer do
expect do
b = enum.enum_for(:each)
b.next
- end.to raise_error
+ end.to raise_error(RuntimeError, "each() called on parallel enumerable twice simultaneously! Bad mojo")
end
end
end