Class: RSpec::Sidekiq::Matchers::BeUnique::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sidekiq/matchers/be_unique.rb

Direct Known Subclasses

SidekiqEnterprise, SidekiqUniqueJobs

Instance Method Summary collapse

Instance Method Details

#descriptionObject



20
21
22
# File 'lib/rspec/sidekiq/matchers/be_unique.rb', line 20

def description
  'be unique in the queue'
end

#failure_messageObject



24
25
26
27
28
29
30
31
# File 'lib/rspec/sidekiq/matchers/be_unique.rb', line 24

def failure_message
  if !interval_matches? && @expected_interval
    "expected #{@klass} to be unique for #{@expected_interval} seconds, "\
    "but its interval was #{actual_interval} seconds"
  else
    "expected #{@klass} to be unique in the queue"
  end
end

#failure_message_when_negatedObject



52
53
54
# File 'lib/rspec/sidekiq/matchers/be_unique.rb', line 52

def failure_message_when_negated
  "expected #{@klass} to not be unique in the queue"
end

#for(interval) ⇒ Object



39
40
41
42
# File 'lib/rspec/sidekiq/matchers/be_unique.rb', line 39

def for(interval)
  @expected_interval = interval
  self
end

#interval_matches?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rspec/sidekiq/matchers/be_unique.rb', line 48

def interval_matches?
  !interval_specified? || actual_interval == @expected_interval
end

#interval_specified?Boolean

Returns:

  • (Boolean)


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

def interval_specified?
  @expected_interval
end

#matches?(job) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/rspec/sidekiq/matchers/be_unique.rb', line 33

def matches?(job)
  @klass = job.is_a?(Class) ? job : job.class
  @actual = @klass.get_sidekiq_options[unique_key]
  !!(value_matches? && interval_matches?)
end