Class: Qe::EnqueueMatcher::Matcher
- Inherits:
-
Object
- Object
- Qe::EnqueueMatcher::Matcher
- Defined in:
- lib/qe/testing/rspec.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scheduled ⇒ Object
readonly
Returns the value of attribute scheduled.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #build_message(base) ⇒ Object
- #datetime? ⇒ Boolean
- #description ⇒ Object
- #does_not_match?(block) ⇒ Boolean
- #failure_message ⇒ Object (also: #failure_message_for_should)
- #failure_message_when_negated ⇒ Object (also: #failure_message_for_should_not)
-
#initialize(worker, scheduled) ⇒ Matcher
constructor
A new instance of Matcher.
- #jobs ⇒ Object
- #matches?(block) ⇒ Boolean
- #on(date) ⇒ Object
- #supports_block_expectations? ⇒ Boolean
- #with(options = nil, &block) ⇒ Object
Constructor Details
#initialize(worker, scheduled) ⇒ Matcher
Returns a new instance of Matcher.
8 9 10 11 12 |
# File 'lib/qe/testing/rspec.rb', line 8 def initialize(worker, scheduled) @worker = worker @options = nil @scheduled = scheduled end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
6 7 8 |
# File 'lib/qe/testing/rspec.rb', line 6 def date @date end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/qe/testing/rspec.rb', line 6 def @options end |
#scheduled ⇒ Object (readonly)
Returns the value of attribute scheduled.
6 7 8 |
# File 'lib/qe/testing/rspec.rb', line 6 def scheduled @scheduled end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
6 7 8 |
# File 'lib/qe/testing/rspec.rb', line 6 def worker @worker end |
Instance Method Details
#build_message(base) ⇒ Object
68 69 70 71 72 |
# File 'lib/qe/testing/rspec.rb', line 68 def (base) base << (( || {}).empty? ? "" : " with #{.inspect}") base << " on #{date.inspect}" if date base end |
#datetime? ⇒ Boolean
80 81 82 |
# File 'lib/qe/testing/rspec.rb', line 80 def datetime? [Date, Time, DateTime].find {|klass| date.kind_of?(klass) } end |
#description ⇒ Object
54 55 56 |
# File 'lib/qe/testing/rspec.rb', line 54 def description "enqueue job for #{worker.inspect} worker" end |
#does_not_match?(block) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/qe/testing/rspec.rb', line 43 def does_not_match?(block) block.call jobs.none? do |job| condition = job[:worker] != worker condition = condition && job[:options] != (.kind_of?(Proc) ? .call : ) if condition = condition && job[:run_at].to_i != date.to_i if date condition end end |
#failure_message ⇒ Object Also known as: failure_message_for_should
58 59 60 |
# File 'lib/qe/testing/rspec.rb', line 58 def "expect #{worker.inspect} to be enqueued" end |
#failure_message_when_negated ⇒ Object Also known as: failure_message_for_should_not
63 64 65 |
# File 'lib/qe/testing/rspec.rb', line 63 def "expect #{worker.inspect} not to be enqueued" end |
#jobs ⇒ Object
74 75 76 77 78 |
# File 'lib/qe/testing/rspec.rb', line 74 def jobs Qe.jobs.select do |job| scheduled ? job.key?(:run_at) : true end end |
#matches?(block) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/qe/testing/rspec.rb', line 28 def matches?(block) block.call @options = @options.call if @options.respond_to?(:call) result = jobs.any? do |job| condition = job[:worker] == worker condition = condition && datetime? if scheduled condition = condition && job[:options] == (.kind_of?(Proc) ? .call : ) if condition = condition && job[:run_at].to_i == date.to_i if date condition end !!result end |
#on(date) ⇒ Object
23 24 25 26 |
# File 'lib/qe/testing/rspec.rb', line 23 def on(date) @date = date self end |
#supports_block_expectations? ⇒ Boolean
14 15 16 |
# File 'lib/qe/testing/rspec.rb', line 14 def supports_block_expectations? true end |
#with(options = nil, &block) ⇒ Object
18 19 20 21 |
# File 'lib/qe/testing/rspec.rb', line 18 def with( = nil, &block) @options = block || self end |