New helper to test `DiscourseEvents` triggers in RSpec

Previously, we used to test that a DiscourseEvent has been triggered by mocking the method call using Mocha which looks something like:


However, these mocks make test cases super brittle because the test case would fail when another DiscourseEvent that is not “expected” is triggered. As a result, the developer would have to mock every single DiscourseEvent trigger that would trigger even if he is only concerned about testing a single trigger.

To work around this problem, I’ve introduced a new helper, inspired by our MessageBus diagnostic helper, that would track all the events that were triggered when the given block of code is executed.

Examples of how to use the new helper can be found in