2024-04-03 23:20:43 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-05-07 04:12:55 +08:00
|
|
|
module AutomationSpecHelpers
|
|
|
|
def capture_contexts(&blk)
|
|
|
|
DiscourseAutomation::CapturedContext.capture(&blk)
|
|
|
|
end
|
2024-04-03 23:20:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
module DiscourseAutomation::CapturedContext
|
|
|
|
def self.add(context)
|
|
|
|
@contexts << context if @capturing
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.capture
|
|
|
|
raise StandardError, "Nested capture is not supported" if @capturing
|
|
|
|
raise StandardError, "Expecting a block" if !block_given?
|
|
|
|
@capturing = true
|
|
|
|
@contexts = []
|
|
|
|
yield
|
|
|
|
@contexts
|
|
|
|
ensure
|
|
|
|
@capturing = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseAutomation::Scriptable.add("something_about_us") do
|
|
|
|
script do |context|
|
|
|
|
DiscourseAutomation::CapturedContext.add(context)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
triggerables [DiscourseAutomation::Triggers::API_CALL]
|
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseAutomation::Scriptable.add("nothing_about_us") do
|
|
|
|
triggerables [DiscourseAutomation::Triggers::API_CALL]
|
|
|
|
end
|
2024-05-07 04:12:55 +08:00
|
|
|
|
|
|
|
RSpec.configure { |config| config.include AutomationSpecHelpers }
|