Class: RSpec::Sidekiq::Matchers::BeDelayed
- Inherits:
-
Object
- Object
- RSpec::Sidekiq::Matchers::BeDelayed
- Defined in:
- lib/rspec/sidekiq/matchers/be_delayed.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #for(interval) ⇒ Object
-
#initialize(*expected_arguments) ⇒ BeDelayed
constructor
A new instance of BeDelayed.
- #matches?(expected_method) ⇒ Boolean
- #until(time) ⇒ Object
Constructor Details
#initialize(*expected_arguments) ⇒ BeDelayed
Returns a new instance of BeDelayed.
11 12 13 14 15 16 17 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 11 def initialize(*expected_arguments) raise <<~MSG if RSpec::Sidekiq.configuration.sidekiq_gte_7? Use of the be_delayed matcher with Sidekiq 7+ is not possible. Try refactoring to a Sidekiq Job with `perform_at` or `perform_in` and the `have_enqueued_sidekiq_job` matcher MSG @expected_arguments = expected_arguments end |
Instance Method Details
#description ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 19 def description description = 'be delayed' description += " for #{@expected_interval} seconds" if @expected_interval description += " until #{@expected_time}" if @expected_time description += " with arguments #{@expected_arguments}" unless @expected_arguments.empty? description end |
#failure_message ⇒ Object
27 28 29 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 27 def "expected #{@expected_method_receiver}.#{@expected_method.name} to " + description end |
#failure_message_when_negated ⇒ Object
54 55 56 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 54 def "expected #{@expected_method_receiver}.#{@expected_method.name} to not " + description end |
#for(interval) ⇒ Object
31 32 33 34 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 31 def for(interval) @expected_interval = interval self end |
#matches?(expected_method) ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 36 def matches?(expected_method) @expected_method = expected_method @expected_method_receiver = @expected_method.is_a?(UnboundMethod) ? @expected_method.owner : @expected_method.receiver find_job @expected_method, @expected_arguments do |job| if @expected_interval created_enqueued_at = job['enqueued_at'] || job['created_at'] return job['at'].to_i == Time.at(created_enqueued_at.to_f + @expected_interval.to_f).to_i elsif @expected_time return job['at'].to_i == @expected_time.to_i else return true end end false end |
#until(time) ⇒ Object
58 59 60 61 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 58 def until(time) @expected_time = time self end |