Module: RubyReactor::RSpec

Defined in:
lib/ruby_reactor/rspec.rb,
lib/ruby_reactor/rspec/helpers.rb,
lib/ruby_reactor/rspec/matchers.rb,
lib/ruby_reactor/rspec/test_subject.rb,
lib/ruby_reactor/rspec/storage_reset.rb,
lib/ruby_reactor/rspec/sidekiq_helpers.rb,
lib/ruby_reactor/rspec/step_executor_patch.rb

Defined Under Namespace

Modules: Helpers, Matchers, SidekiqHelpers, StepExecutorPatch, StorageReset Classes: TestSubject

Constant Summary collapse

REACTOR_METADATA =

Examples opt into RubyReactor’s RSpec setup (Sidekiq fake mode, storage wipe, snooze knob reset) by declaring ‘type: :reactor`.

{ type: :reactor }.freeze
DEFAULT_SNOOZE_BASE_DELAY =
5
DEFAULT_SNOOZE_JITTER =
5
DEFAULT_SNOOZE_MAX_ATTEMPTS =
20

Class Method Summary collapse

Class Method Details

.configure(config) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ruby_reactor/rspec.rb', line 19

def self.configure(config)
  require_relative "rspec/step_executor_patch"

  config.include RubyReactor::RSpec::Helpers
  config.include RubyReactor::RSpec::Matchers
  config.include RubyReactor::RSpec::SidekiqHelpers, REACTOR_METADATA

  ::RubyReactor::Executor::StepExecutor.prepend(RubyReactor::RSpec::StepExecutorPatch)
  StorageReset.install!

  config.before(:each, REACTOR_METADATA) do
    RubyReactor::RSpec.prepare_example!
  end
end

.prepare_example!Object

Idempotent setup invoked before each ‘type: :reactor` example. Restores Sidekiq fake mode, clears the queues, wipes the storage adapter, and rolls back snooze knobs so cross-example bleed-through can’t happen.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby_reactor/rspec.rb', line 37

def self.prepare_example!
  if defined?(::Sidekiq::Testing)
    begin
      ::Sidekiq::Testing.fake! unless ::Sidekiq::Testing.fake?
    rescue ::Sidekiq::Testing::TestModeAlreadySetError
      # Nested fake!/inline! block already active in this thread; leave it.
    end
    ::Sidekiq::Worker.clear_all
  end

  adapter = ::RubyReactor.configuration.storage_adapter
  adapter.reset! if adapter.respond_to?(:reset!)

  ::RubyReactor.configuration.lock_snooze_base_delay = DEFAULT_SNOOZE_BASE_DELAY
  ::RubyReactor.configuration.lock_snooze_jitter = DEFAULT_SNOOZE_JITTER
  ::RubyReactor.configuration.lock_snooze_max_attempts = DEFAULT_SNOOZE_MAX_ATTEMPTS
end