summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-05-29 12:56:42 -0700
committerTim Smith <tsmith84@gmail.com>2020-06-23 09:24:27 -0700
commitec53b7eee247a39c932222fe6ad4e7f5938140d4 (patch)
tree095978face8df20d67a8fc57339c32d9d7d4c09c /spec/unit
parenta34fd84377c705fcdf3a415b40300e11c3cacf35 (diff)
downloadchef-rspec_15.tar.gz
Fix rspec warning about `not_to raise_error` with a specific exception.rspec_15
WARNING: Using `expect { }.not_to raise_error(SpecificErrorClass)` risks false positives, since literally any other error would cause the expectation to pass, including those raised by Ruby (e.g. NoMethodError, NameError and ArgumentError), meaning the code you are intending to test may not even get reached. Instead consider using `expect { }.not_to raise_error` or `expect { }.to raise_error(DifferentSpecificErrorClass)`. This message can be suppressed by setting: `RSpec::Expectations.configuration.on_potential_false_positives = :nothing`. Called from /Users/pete/work/chef/spec/unit/resource_spec.rb:381:in `block (4 levels) in <top (required)>'. Signed-off-by: Pete Higgins <pete@peterhiggins.org>
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/mixin/user_context_spec.rb4
-rw-r--r--spec/unit/property_spec.rb2
-rw-r--r--spec/unit/resource/windows_dns_record_spec.rb6
-rw-r--r--spec/unit/resource/windows_dns_zone_spec.rb4
-rw-r--r--spec/unit/resource/windows_task_spec.rb2
-rw-r--r--spec/unit/resource/windows_uac_spec.rb4
-rw-r--r--spec/unit/resource/yum_repository_spec.rb42
-rw-r--r--spec/unit/resource_spec.rb2
8 files changed, 33 insertions, 33 deletions
diff --git a/spec/unit/mixin/user_context_spec.rb b/spec/unit/mixin/user_context_spec.rb
index f865d921f8..d00bb51f78 100644
--- a/spec/unit/mixin/user_context_spec.rb
+++ b/spec/unit/mixin/user_context_spec.rb
@@ -82,12 +82,12 @@ describe "a class that mixes in user_context" do
let(:block_parameter) { Proc.new { raise UserContextTextException } }
it "raises the exception raised by the block" do
- expect { instance_with_user_context.with_context("kamilah", nil, "chef4life", &block_parameter) }.not_to raise_error(UserContextTestException)
+ expect { instance_with_user_context.with_context("kamilah", nil, "chef4life", &block_parameter) }.not_to raise_error
end
it "closes the logon session so resources are not leaked" do
expect(logon_session).to receive(:close)
- expect { instance_with_user_context.with_context("kamilah", nil, "chef4life", &block_parameter) }.not_to raise_error(UserContextTestException)
+ expect { instance_with_user_context.with_context("kamilah", nil, "chef4life", &block_parameter) }.not_to raise_error
end
end
end
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 97211c57d4..cf2b98198a 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -121,7 +121,7 @@ describe "Chef::Resource.property" do
context "deprecated properties" do
it "does not create a deprecation warning on definition" do
- expect { resource_class.class_eval { property :x, String, deprecated: 10 } }.not_to raise_error Chef::Exceptions::DeprecatedFeatureError
+ expect { resource_class.class_eval { property :x, String, deprecated: 10 } }.not_to raise_error
end
with_property ":x, deprecated: 'a deprecated property'" do
diff --git a/spec/unit/resource/windows_dns_record_spec.rb b/spec/unit/resource/windows_dns_record_spec.rb
index d4f9cd06a8..acf8824e89 100644
--- a/spec/unit/resource/windows_dns_record_spec.rb
+++ b/spec/unit/resource/windows_dns_record_spec.rb
@@ -29,15 +29,15 @@ describe Chef::Resource::WindowsDnsRecord do
end
it "the record_type property accepts 'CNAME'" do
- expect { resource.record_type "CNAME" }.not_to raise_error(ArgumentError)
+ expect { resource.record_type "CNAME" }.not_to raise_error
end
it "the record_type property accepts 'ARecord'" do
- expect { resource.record_type "ARecord" }.not_to raise_error(ArgumentError)
+ expect { resource.record_type "ARecord" }.not_to raise_error
end
it "the record_type property accepts 'PTR'" do
- expect { resource.record_type "PTR" }.not_to raise_error(ArgumentError)
+ expect { resource.record_type "PTR" }.not_to raise_error
end
it "the resource raises an ArgumentError if invalid record_type is set" do
diff --git a/spec/unit/resource/windows_dns_zone_spec.rb b/spec/unit/resource/windows_dns_zone_spec.rb
index 00bb268617..806c565b81 100644
--- a/spec/unit/resource/windows_dns_zone_spec.rb
+++ b/spec/unit/resource/windows_dns_zone_spec.rb
@@ -29,11 +29,11 @@ describe Chef::Resource::WindowsDnsZone do
end
it "the server_type property accepts 'Standalone'" do
- expect { resource.server_type "Standalone" }.not_to raise_error(ArgumentError)
+ expect { resource.server_type "Standalone" }.not_to raise_error
end
it "the server_type property accepts 'Domain'" do
- expect { resource.server_type "Domain" }.not_to raise_error(ArgumentError)
+ expect { resource.server_type "Domain" }.not_to raise_error
end
it "the resource raises an ArgumentError if invalid server_type is set" do
diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb
index 1ef245abeb..c39dcde115 100644
--- a/spec/unit/resource/windows_task_spec.rb
+++ b/spec/unit/resource/windows_task_spec.rb
@@ -144,7 +144,7 @@ describe Chef::Resource::WindowsTask, :windows_only do
resource.frequency :once
resource.random_delay "20"
resource.start_time "15:00"
- expect { resource.after_created }.to_not raise_error(ArgumentError, "`random_delay` property is supported only for frequency :once, :minute, :hourly, :daily, :weekly and :monthly")
+ expect { resource.after_created }.to_not raise_error
end
it "raises error for invalid random_delay" do
diff --git a/spec/unit/resource/windows_uac_spec.rb b/spec/unit/resource/windows_uac_spec.rb
index 85b1504d79..a82ca65421 100644
--- a/spec/unit/resource/windows_uac_spec.rb
+++ b/spec/unit/resource/windows_uac_spec.rb
@@ -26,7 +26,7 @@ describe Chef::Resource::WindowsUac do
%i{no_prompt secure_prompt_for_creds secure_prompt_for_consent prompt_for_creds prompt_for_consent prompt_for_consent_non_windows_binaries}.each do |val|
it "the consent_behavior_admins property accepts :#{val}" do
- expect { resource.consent_behavior_admins val }.not_to raise_error(ArgumentError)
+ expect { resource.consent_behavior_admins val }.not_to raise_error
end
end
@@ -36,7 +36,7 @@ describe Chef::Resource::WindowsUac do
%i{auto_deny secure_prompt_for_creds prompt_for_creds}.each do |val|
it "the consent_behavior_users property accepts :#{val}" do
- expect { resource.consent_behavior_users val }.not_to raise_error(ArgumentError)
+ expect { resource.consent_behavior_users val }.not_to raise_error
end
end
diff --git a/spec/unit/resource/yum_repository_spec.rb b/spec/unit/resource/yum_repository_spec.rb
index e4316f36d1..36d88450d1 100644
--- a/spec/unit/resource/yum_repository_spec.rb
+++ b/spec/unit/resource/yum_repository_spec.rb
@@ -73,52 +73,52 @@ describe Chef::Resource::YumRepository do
end
it "the timeout property expects numeric Strings" do
- expect { resource.timeout "123" }.not_to raise_error(ArgumentError)
+ expect { resource.timeout "123" }.not_to raise_error
expect { resource.timeout "123foo" }.to raise_error(ArgumentError)
end
it "the priority property expects numeric Strings from '1' to '99'" do
- expect { resource.priority "99" }.not_to raise_error(ArgumentError)
- expect { resource.priority "1" }.not_to raise_error(ArgumentError)
+ expect { resource.priority "99" }.not_to raise_error
+ expect { resource.priority "1" }.not_to raise_error
expect { resource.priority "100" }.to raise_error(ArgumentError)
expect { resource.priority "0" }.to raise_error(ArgumentError)
end
it "the failovermethod property accepts 'priority' or 'roundrobin'" do
- expect { resource.failovermethod "priority" }.not_to raise_error(ArgumentError)
- expect { resource.failovermethod "roundrobin" }.not_to raise_error(ArgumentError)
+ expect { resource.failovermethod "priority" }.not_to raise_error
+ expect { resource.failovermethod "roundrobin" }.not_to raise_error
expect { resource.failovermethod "bob" }.to raise_error(ArgumentError)
end
it "the http_caching property accepts 'packages', 'all', or 'none'" do
- expect { resource.http_caching "packages" }.not_to raise_error(ArgumentError)
- expect { resource.http_caching "all" }.not_to raise_error(ArgumentError)
- expect { resource.http_caching "none" }.not_to raise_error(ArgumentError)
+ expect { resource.http_caching "packages" }.not_to raise_error
+ expect { resource.http_caching "all" }.not_to raise_error
+ expect { resource.http_caching "none" }.not_to raise_error
expect { resource.http_caching "bob" }.to raise_error(ArgumentError)
end
it "the metadata_expire property accepts a time value or 'never'" do
- expect { resource.metadata_expire "100" }.not_to raise_error(ArgumentError)
- expect { resource.metadata_expire "100d" }.not_to raise_error(ArgumentError)
- expect { resource.metadata_expire "100h" }.not_to raise_error(ArgumentError)
- expect { resource.metadata_expire "100m" }.not_to raise_error(ArgumentError)
- expect { resource.metadata_expire "never" }.not_to raise_error(ArgumentError)
+ expect { resource.metadata_expire "100" }.not_to raise_error
+ expect { resource.metadata_expire "100d" }.not_to raise_error
+ expect { resource.metadata_expire "100h" }.not_to raise_error
+ expect { resource.metadata_expire "100m" }.not_to raise_error
+ expect { resource.metadata_expire "never" }.not_to raise_error
expect { resource.metadata_expire "100s" }.to raise_error(ArgumentError)
end
it "the mirror_expire property accepts a time value" do
- expect { resource.mirror_expire "100" }.not_to raise_error(ArgumentError)
- expect { resource.mirror_expire "100d" }.not_to raise_error(ArgumentError)
- expect { resource.mirror_expire "100h" }.not_to raise_error(ArgumentError)
- expect { resource.mirror_expire "100m" }.not_to raise_error(ArgumentError)
+ expect { resource.mirror_expire "100" }.not_to raise_error
+ expect { resource.mirror_expire "100d" }.not_to raise_error
+ expect { resource.mirror_expire "100h" }.not_to raise_error
+ expect { resource.mirror_expire "100m" }.not_to raise_error
expect { resource.mirror_expire "never" }.to raise_error(ArgumentError)
end
it "the mirrorlist_expire property accepts a time value" do
- expect { resource.mirrorlist_expire "100" }.not_to raise_error(ArgumentError)
- expect { resource.mirrorlist_expire "100d" }.not_to raise_error(ArgumentError)
- expect { resource.mirrorlist_expire "100h" }.not_to raise_error(ArgumentError)
- expect { resource.mirrorlist_expire "100m" }.not_to raise_error(ArgumentError)
+ expect { resource.mirrorlist_expire "100" }.not_to raise_error
+ expect { resource.mirrorlist_expire "100d" }.not_to raise_error
+ expect { resource.mirrorlist_expire "100h" }.not_to raise_error
+ expect { resource.mirrorlist_expire "100m" }.not_to raise_error
expect { resource.mirrorlist_expire "never" }.to raise_error(ArgumentError)
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 2ea0f18368..9396f329d8 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -378,7 +378,7 @@ describe Chef::Resource do
it "does not propagate validation errors" do
resource_class = Class.new(Chef::Resource) { property :foo, String, required: true }
resource = resource_class.new("required_property_tests")
- expect { resource.to_text }.to_not raise_error Chef::Exceptions::ValidationFailed
+ expect { resource.to_text }.to_not raise_error
end
end
end