mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Remove raise_error negative block to fix RSpec warnings
Currently RSpec warns these specs like this:
```
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 /path/to/spec/lib/stripe/payment_intent_validator_spec.rb:53:in `block (7 levels) in <main>'.
```
The warnings are super accurate in this particular case: the inner
assertion is not actually getting reached due to a previous unrelated
error.
Since there's an inner assertion already, I think it's best to
completely remove to `raise_error` negative block, since it just hides
errors and buys us nothing.
By removing it, the underlying error surfaces:
```
1) Stripe::PaymentIntentValidator#call as a guest when payment intent is valid valid non-3D credit cards are correctly handled behaves like payments intents from Visa returns payment intent id and does not raise
Failure/Error:
create(:payment, amount: payment_intent.amount, payment_method:,
response_code: payment_intent.id, source: pm_card)
NoMethodError:
undefined method `has_query_constraints?' for Stripe::PaymentMethod:Class
elsif (klass || self.klass).has_query_constraints? || options[:query_constraints]
^^^^^^^^^^^^^^^^^^^^^^^
Shared Example Group: "payments intents" called from ./spec/lib/stripe/payment_intent_validator_spec.rb:75
# ./spec/lib/stripe/payment_intent_validator_spec.rb:16:in `block (3 levels) in <main>'
# ./spec/lib/stripe/payment_intent_validator_spec.rb:19:in `block (3 levels) in <main>'
# ./spec/lib/stripe/payment_intent_validator_spec.rb:53:in `block (7 levels) in <main>'
# ./spec/base_spec_helper.rb:208:in `block (2 levels) in <main>'
# ./spec/base_spec_helper.rb:155:in `block (3 levels) in <main>'
# ./spec/base_spec_helper.rb:155:in `block (2 levels) in <main>'
# -e:1:in `<main>'
```
This commit is contained in:
@@ -50,13 +50,11 @@ RSpec.describe Stripe::PaymentIntentValidator do
|
||||
Stripe::PaymentIntent.confirm(payment_intent.id)
|
||||
end
|
||||
it "returns payment intent id and does not raise" do
|
||||
expect {
|
||||
result = validator.call
|
||||
expect(result).to eq(
|
||||
"this doesn't affect the spec because it never runs, due to a previous error." \
|
||||
"Yet, since this is wrapper in a negative raise_error block, it still passes"
|
||||
)
|
||||
}.not_to raise_error Stripe::StripeError
|
||||
result = validator.call
|
||||
expect(result).to eq(
|
||||
"this doesn't affect the spec because it never runs, due to a previous error." \
|
||||
"Yet, since this is wrapper in a negative raise_error block, it still passes"
|
||||
)
|
||||
end
|
||||
|
||||
it "captures the payment" do
|
||||
@@ -197,13 +195,11 @@ RSpec.describe Stripe::PaymentIntentValidator do
|
||||
Stripe::PaymentIntent.confirm(payment_intent.id)
|
||||
end
|
||||
it "returns payment intent id and does not raise" do
|
||||
expect {
|
||||
result = validator.call
|
||||
expect(result).to eq(
|
||||
"this doesn't affect the spec because it never runs, due to a previous error." \
|
||||
"Yet, since this is wrapper in a negative raise_error block, it still passes"
|
||||
)
|
||||
}.not_to raise_error Stripe::StripeError
|
||||
result = validator.call
|
||||
expect(result).to eq(
|
||||
"this doesn't affect the spec because it never runs, due to a previous error." \
|
||||
"Yet, since this is wrapper in a negative raise_error block, it still passes"
|
||||
)
|
||||
end
|
||||
|
||||
it "captures the payment" do
|
||||
|
||||
Reference in New Issue
Block a user