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.
9 10 11 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 9 def initialize(*expected_arguments) @expected_arguments = expected_arguments end |
Instance Method Details
#description ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 13 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
21 22 23 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 21 def "expected #{@expected_method.receiver}.#{@expected_method.name} to " + description end |
#failure_message_when_negated ⇒ Object
46 47 48 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 46 def "expected #{@expected_method.receiver}.#{@expected_method.name} to not " + description end |
#for(interval) ⇒ Object
25 26 27 28 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 25 def for(interval) @expected_interval = interval self end |
#matches?(expected_method) ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 30 def matches?(expected_method) @expected_method = expected_method find_job @expected_method, @expected_arguments do |job| if @expected_interval return job['at'].to_i == job['enqueued_at'].to_i + @expected_interval elsif @expected_time return job['at'].to_i == @expected_time.to_i else return true end end false end |
#until(time) ⇒ Object
50 51 52 53 |
# File 'lib/rspec/sidekiq/matchers/be_delayed.rb', line 50 def until(time) @expected_time = time self end |