Skip to content

Commit d95fc71

Browse files
committed
Standardize event name formatting in assert_event_reported
This change adds `.inspect` to the event name in `assert_event_reported`'s failure message, making it consistent with how `payload` and `tags` and `assert_events_reported` are displayed. `.inspect` is better and it helps distinguish between event names that are strings vs symbols and is now consistent with the other fields.
1 parent 5d25857 commit d95fc71

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

activesupport/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* Standardize event name formatting in `assert_event_reported` error messages.
2+
3+
The event name in failure messages now uses `.inspect` (e.g., `name: "user.created"`)
4+
to match `assert_events_reported` and provide type clarity between strings and symbols.
5+
This only affects tests that assert on the failure message format itself.
6+
7+
*George Ma*
8+
19
* Fix `Enumerable#sole` to return the full tuple instead of just the first element of the tuple.
210

311
*Olivier Bellone*

activesupport/lib/active_support/testing/event_reporter_assertions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def assert_event_reported(name, payload: nil, tags: {}, &block)
149149
event.event_data
150150
else
151151
message = "Expected an event to be reported matching:\n " \
152-
"name: #{name}\n " \
152+
"name: #{name.inspect}\n " \
153153
"payload: #{payload.inspect}\n " \
154154
"tags: #{tags.inspect}\n" \
155155
"but none of the #{events.size} reported events matched:\n " \

activesupport/test/testing/event_reporter_assertions_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class EventReporterAssertionsTest < ActiveSupport::TestCase
103103
end
104104

105105
assert_match(/Expected an event to be reported matching:/, e.message)
106-
assert_match(/name: user\.created/, e.message)
106+
assert_match(/name: "user\.created"/, e.message)
107107
assert_match(/but none of the 1 reported events matched:/, e.message)
108108
assert_match(/another\.event/, e.message)
109109
end

0 commit comments

Comments
 (0)