Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assert_error_reported and assert_no_error_reported #46029

Merged
merged 1 commit into from Sep 16, 2022

Conversation

casperisfine
Copy link
Contributor

Allows to easily asserts an error happened but was handled

report = assert_error_reported(IOError) do
  # ...
end
assert_equal "Oops", report.error.message
assert_equal "admin", report.context[:section]
assert_equal :warning, report.severity
assert_predicate report, :handled?

The matching is on purpose limited to a single class matching, at least in the documentation, as I don't think it would be a good idea to add more complex matchers, as they would get unwidly.

That being said, I use === for matching, so you could pass a proc to do more complex matching, it would be not handle nothing matching properly.

@@ -95,6 +95,7 @@ def self.eager_load!
cattr_accessor :test_order # :nodoc:
cattr_accessor :test_parallelization_threshold, default: 50 # :nodoc:

@error_reporter = ActiveSupport::ErrorReporter.new
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changing a bit how the error reporter works. Now it's just always available on ActiveSupport.error_reporter and all other ways to access it are just delegators.

Allows to easily asserts an error happened but was handled

```ruby
report = assert_error_reported(IOError) do
  # ...
end
assert_equal "Oops", report.error.message
assert_equal "admin", report.context[:section]
assert_equal :warning, report.severity
assert_predicate report, :handled?
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants