Class: RSpec::Sidekiq::Matchers::HaveJobOption

Inherits:
Object
  • Object
show all
Includes:
JobOptionNormalization
Defined in:
lib/rspec/sidekiq/matchers/have_job_options.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ HaveJobOption

Returns a new instance of HaveJobOption.



44
45
46
47
# File 'lib/rspec/sidekiq/matchers/have_job_options.rb', line 44

def initialize(key, value)
  @expected_key = normalize_key(key)
  @expected_value = normalize_value(value)
end

Instance Method Details

#descriptionObject



49
50
51
# File 'lib/rspec/sidekiq/matchers/have_job_options.rb', line 49

def description
  "have sidekiq option #{@expected_key}: #{formatted(@expected_value)}"
end

#failure_messageObject



61
62
63
64
65
66
67
# File 'lib/rspec/sidekiq/matchers/have_job_options.rb', line 61

def failure_message
  if !@actual_present
    "expected #{@klass} to have sidekiq option #{@expected_key} but it was not set"
  else
    "expected #{@klass} to have sidekiq option #{@expected_key}: #{formatted(@expected_value)} but got #{formatted(@actual_value)}"
  end
end

#failure_message_when_negatedObject



69
70
71
# File 'lib/rspec/sidekiq/matchers/have_job_options.rb', line 69

def failure_message_when_negated
  "expected #{@klass} to not have sidekiq option #{@expected_key}: #{formatted(@expected_value)}"
end

#matches?(job) ⇒ Boolean

Returns:



53
54
55
56
57
58
59
# File 'lib/rspec/sidekiq/matchers/have_job_options.rb', line 53

def matches?(job)
  @klass = job.is_a?(Class) ? job : job.class
  @options = @klass.get_sidekiq_options
  @actual_present = @options.key?(@expected_key)
  @actual_value = @options[@expected_key]
  @actual_present && RSpec::Support::FuzzyMatcher.values_match?(@expected_value, @actual_value)
end