Module: Webhookdb::SpecHelpers::Async

Defined in:
lib/webhookdb/spec_helpers/async.rb

Class Method Summary collapse

Class Method Details

.included(context) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/webhookdb/spec_helpers/async.rb', line 10

def self.included(context)
  Sidekiq::Testing.inline!
  Amigo::QueueBackoffJob.reset

  context.before(:each) do |example|
    if (sidekiq_mode = example.[:sidekiq])
      Sidekiq::Testing.send(:"#{sidekiq_mode}!")
    else
      Sidekiq::Testing.inline!
    end
    Webhookdb::Postgres.do_not_defer_events = true if example.[:do_not_defer_events]
    if example.[:slack]
      Webhookdb::Slack.http_client = Webhookdb::Slack::NoOpHttpClient.new
      Webhookdb::Slack.suppress_all = false
    end
    if example.[:sentry]
      Webhookdb::Sentry.dsn = "http://public:[email protected]/someproject"
      Webhookdb::Sentry.run_after_configured_hooks
    end
  end

  context.after(:each) do |example|
    Webhookdb::Postgres.do_not_defer_events = false if example.[:do_not_defer_events]
    if example.[:slack]
      Webhookdb::Slack.http_client = nil
      Webhookdb::Slack.reset_configuration
    end
    Webhookdb::Sentry.reset_configuration if example.[:sentry]
    Sidekiq::Queues.clear_all if example.[:sidekiq] && Sidekiq::Testing.fake?
  end
  super
end

.job_hash(cls, **more) ⇒ Object



43
44
45
46
47
# File 'lib/webhookdb/spec_helpers/async.rb', line 43

module_function def job_hash(cls, **more)
  params = {"class" => cls.to_s}
  params.merge!(more.stringify_keys)
  return hash_including(params)
end