Class: RSpec::ActiveJob::Matchers::EnqueueA
- Inherits:
-
Object
- Object
- RSpec::ActiveJob::Matchers::EnqueueA
- Defined in:
- lib/rspec/active_job/enqueue_a.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(job_class = nil) ⇒ EnqueueA
constructor
A new instance of EnqueueA.
- #matches?(actual) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
- #with(*args) ⇒ Object
Constructor Details
#initialize(job_class = nil) ⇒ EnqueueA
Returns a new instance of EnqueueA.
7 8 9 |
# File 'lib/rspec/active_job/enqueue_a.rb', line 7 def initialize(job_class = nil) @job_class = job_class end |
Instance Method Details
#description ⇒ Object
64 65 66 67 68 |
# File 'lib/rspec/active_job/enqueue_a.rb', line 64 def description return "enqueue a job" unless job_class return "enqueue a #{job_class.name}" unless argument_list_matcher "enqueue a #{job_class.name} with #{argument_list_matcher.expected_args}" end |
#failure_message ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rspec/active_job/enqueue_a.rb', line 30 def unless enqueued_something? return "expected to enqueue a #{job_class || 'job'}, enqueued nothing" end unless enqueued_correct_class? return "expected to enqueue a #{job_class}, " \ "enqueued a #{enqueued_jobs.last[:job]}" end "expected to enqueue a #{job_class} with " \ "#{argument_list_matcher.expected_args}, but enqueued with " \ "#{new_jobs_with_correct_class.first[:args]}" end |
#failure_message_when_negated ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rspec/active_job/enqueue_a.rb', line 45 def return "expected to not enqueue a job" unless job_class = "expected to not enqueue a #{job_class}" if @argument_list_matcher += " with #{argument_list_matcher.expected_args}" end += ", but enqueued a #{enqueued_jobs.last[:job]}" return unless enqueued_correct_class? + " with #{new_jobs_with_correct_class.first[:args]}" end |
#matches?(actual) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rspec/active_job/enqueue_a.rb', line 11 def matches?(actual) raise "must use a block with enqueue_a" if !actual.is_a?(Proc) && @job_class if actual.is_a?(Proc) @before_jobs = enqueued_jobs.dup actual.call enqueued_something? && enqueued_correct_class? && with_correct_args? else @job_class = actual @before_jobs = [] enqueued_something? && enqueued_correct_class? && with_correct_args? end end |
#supports_block_expectations? ⇒ Boolean
60 61 62 |
# File 'lib/rspec/active_job/enqueue_a.rb', line 60 def supports_block_expectations? true end |
#with(*args) ⇒ Object
25 26 27 28 |
# File 'lib/rspec/active_job/enqueue_a.rb', line 25 def with(*args) @argument_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(*args) self end |