Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Consider deprecating expect { }.not_to raise_error(SpecificErrorClass) #231

@myronmarston

Description

@myronmarston

An expression like expect { }.not_to raise_error is fine, as it expresses intent (particularly when paired with a corresponding example that demonstrates when a particular error is raised), but expect { }.not_to raise_error(SpecificErrorClass) is dangerous. It's prone to producing false positives. Consider:

expect {
  expect(some_helper(foo)).to eq(:bar)
}.not_to raise_error(SomeError)

With this in place, it's impossible for the inner expectation to ever cause the example to fail. When the inner expectation fails, it raises a RSpec::Expectations::ExpectationNotMetError, but this is not a SomeError, so the outer expectation causes it to pass.

Thus, I think we should deprecate a specific error class with the negative raise_error matching. In 3.0 it'd be nice to disallow it entirely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions