Class: RSpec::SidekiqPro::Matchers::EnqueueSidekiqJobs

Inherits:
Object
  • Object
show all
Includes:
JobMatcher
Defined in:
lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb

Instance Attribute Summary

Attributes included from JobMatcher

#actual_jobs, #expected_arguments, #expected_batch, #expected_count, #expected_interval, #expected_least_count, #expected_less_count, #expected_more_count, #expected_most_count, #expected_schedule, #expected_timestamp, #expected_without_batch, #worker_class

Instance Method Summary collapse

Methods included from JobMatcher

#actual_jobs_details_in_failure_message, #actual_jobs_size_in_failure_message, #at, #at_least, #at_most, #batch_match?, #exactly, #expectations_in_failure_message, #expected_interval_output, #expected_job_description, #failure_message_diff, #filter_jobs, #in, #job_details_in_failure_message, #less_than, #more_than, #normalize_arguments, #once, #output_arguments, #output_batch, #output_schedule, #times, #twice, #with, #within_batch, #without_batch

Constructor Details

#initialize(worker_class) ⇒ EnqueueSidekiqJobs

Returns a new instance of EnqueueSidekiqJobs.



11
12
13
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 11

def initialize(worker_class)
  @worker_class = worker_class
end

Instance Method Details

#capture_actual_jobs(block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 43

def capture_actual_jobs(block)
  before = worker_class.jobs.dup
  result = block.call

  if @expected_arguments.is_a?(Proc)
    arguments = @expected_arguments.call(result)
    raise "arguments returned from a proc are expected to be an Array" unless arguments.is_a?(Array)

    @expected_arguments = normalize_arguments(arguments)
  end

  worker_class.jobs - before
end

#descriptionObject



31
32
33
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 31

def description
  "enqueue #{expected_job_description}"
end

#does_not_match?(block) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 27

def does_not_match?(block)
  super(capture_actual_jobs(block))
end

#failure_messageObject



35
36
37
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 35

def failure_message
  "expected to enqueue #{worker_class} job\n#{failure_message_diff}"
end

#failure_message_when_negatedObject



39
40
41
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 39

def failure_message_when_negated
  "expected not to enqueue #{worker_class} job\n#{failure_message_diff}"
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 23

def matches?(block)
  super(capture_actual_jobs(block))
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 15

def supports_block_expectations?
  true
end

#supports_value_expectations?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rspec/sidekiq_pro/matchers/enqueue_sidekiq_jobs.rb', line 19

def supports_value_expectations?
  false
end