Module: RSpec::Sidekiq::Matchers

Includes:
Mocks::ArgumentMatchers
Defined in:
lib/rspec/sidekiq/matchers/base.rb,
lib/rspec/sidekiq/matchers/be_unique.rb,
lib/rspec/sidekiq/matchers/be_delayed.rb,
lib/rspec/sidekiq/matchers/be_retryable.rb,
lib/rspec/sidekiq/matchers/be_expired_in.rb,
lib/rspec/sidekiq/matchers/save_backtrace.rb,
lib/rspec/sidekiq/matchers/be_processed_in.rb,
lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb,
lib/rspec/sidekiq/matchers/have_enqueued_sidekiq_job.rb

Defined Under Namespace

Classes: Base, BeDelayed, BeExpiredIn, BeProcessedIn, BeRetryable, BeUnique, EnqueueSidekiqJob, EnqueuedJob, EnqueuedJobs, HaveEnqueuedSidekiqJob, JobArguments, JobOptionParser, SaveBacktrace

Instance Method Summary collapse

Instance Method Details

#be_delayed(*expected_arguments) ⇒ Object



6
7
8
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 6

def be_delayed(*expected_arguments)
  BeDelayed.new(*expected_arguments)
end

#be_expired_in(expected_argument) ⇒ Object



4
5
6
# File 'lib/rspec/sidekiq/matchers/be_expired_in.rb', line 4

def be_expired_in(expected_argument)
  BeExpiredIn.new(expected_argument)
end

#be_processed_in(expected_queue) ⇒ Object



4
5
6
# File 'lib/rspec/sidekiq/matchers/be_processed_in.rb', line 4

def be_processed_in(expected_queue)
  BeProcessedIn.new expected_queue
end

#be_retryable(expected_retry) ⇒ Object



4
5
6
# File 'lib/rspec/sidekiq/matchers/be_retryable.rb', line 4

def be_retryable(expected_retry)
  BeRetryable.new expected_retry
end

#be_uniqueObject



4
5
6
# File 'lib/rspec/sidekiq/matchers/be_unique.rb', line 4

def be_unique
  BeUnique.new
end

#enqueue_sidekiq_job(job_class = nil) ⇒ Object

Passes if a Job is enqueued as the result of a block. Chainable ‘with` for arguments, `on` for queue, `at` for queued for a specific time, and `in` for a specific interval delay to being queued, `immediately` for queued without delay.

Examples:


expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job

# A specific job class
expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job(AwesomeJob)

# with specific arguments
expect { AwesomeJob.perform_async "Awesome!" }.to enqueue_sidekiq_job.with("Awesome!")

# On a specific queue
expect { AwesomeJob.set(queue: "high").perform_async }.to enqueue_sidekiq_job.on("high")

# At a specific datetime
specific_time = 1.hour.from_now
expect { AwesomeJob.perform_at(specific_time) }.to enqueue_sidekiq_job.at(specific_time)

# In a specific interval (be mindful of freezing or managing time here)
freeze_time do
  expect { AwesomeJob.perform_in(1.hour) }.to enqueue_sidekiq_job.in(1.hour)
end

# Without any delay
expect { AwesomeJob.perform_async }.to enqueue_sidekiq_job.immediately
expect { AwesomeJob.perform_at(1.hour.ago) }.to enqueue_sidekiq_job.immediately

## Composable

expect do
  AwesomeJob.perform_async
  OtherJob.perform_async
end.to enqueue_sidekiq_job(AwesomeJob).and enqueue_sidekiq_job(OtherJob)


81
82
83
# File 'lib/rspec/sidekiq/matchers/enqueue_sidekiq_job.rb', line 81

def enqueue_sidekiq_job(job_class = nil)
  EnqueueSidekiqJob.new(job_class)
end

#have_enqueued_sidekiq_job(*expected_arguments) ⇒ Object



4
5
6
# File 'lib/rspec/sidekiq/matchers/have_enqueued_sidekiq_job.rb', line 4

def have_enqueued_sidekiq_job(*expected_arguments)
  HaveEnqueuedSidekiqJob.new expected_arguments
end

#save_backtrace(expected_backtrace = true) ⇒ Object



4
5
6
# File 'lib/rspec/sidekiq/matchers/save_backtrace.rb', line 4

def save_backtrace(expected_backtrace=true)
  SaveBacktrace.new expected_backtrace
end