discourse/spec/support/discourse_event_helper.rb
Sam Saffron 4ea21fa2d0 DEV: use #frozen_string_literal: true on all spec
This change both speeds up specs (less strings to allocate) and helps catch
cases where methods in Discourse are mutating inputs.

Overall we will be migrating everything to use #frozen_string_literal: true
it will take a while, but this is the first and safest move in this direction
2019-04-30 10:27:42 +10:00

27 lines
552 B
Ruby

# frozen_string_literal: true
module DiscourseEvent::TestHelper
def trigger(event_name, *params)
super(event_name, *params)
if @events_trigger
@events_trigger << { event_name: event_name, params: params }
end
end
def track_events
@events_trigger = events_trigger = []
yield
@events_trigger = nil
events_trigger
end
def track(event_type)
events = track_events { yield }
events.find { |e| e[:event_name] == event_type }
end
end
DiscourseEvent.singleton_class.prepend DiscourseEvent::TestHelper