Class: RSpec::Que::Matchers::QueueUp

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Matchers::Composable
Defined in:
lib/rspec/que/queue_up.rb,
lib/rspec/que/queue_up/queued_at.rb,
lib/rspec/que/queue_up/queue_count.rb,
lib/rspec/que/queue_up/queued_args.rb,
lib/rspec/que/queue_up/queued_class.rb,
lib/rspec/que/queue_up/queued_priority.rb,
lib/rspec/que/queue_up/queued_something.rb

Defined Under Namespace

Classes: QueueCount, QueuedArgs, QueuedAt, QueuedClass, QueuedPriority, QueuedSomething

Instance Method Summary collapse

Constructor Details

#initialize(job_class = nil) ⇒ QueueUp

Returns a new instance of QueueUp.



21
22
23
24
25
26
27
# File 'lib/rspec/que/queue_up.rb', line 21

def initialize(job_class = nil)
  @matchers = [QueuedSomething.new]
  @matchers << QueuedClass.new(job_class) if job_class
  @count_matcher = QueueCount.new(self, QueueCount::EXACTLY, 1)
  @job_class = job_class
  @stages = []
end

Instance Method Details

#at(the_time) ⇒ Object



49
50
51
52
# File 'lib/rspec/que/queue_up.rb', line 49

def at(the_time)
  @matchers << QueuedAt.new(the_time)
  self
end

#descriptionObject



88
89
90
# File 'lib/rspec/que/queue_up.rb', line 88

def description
  "queues up a #{job_description}"
end

#failure_messageObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rspec/que/queue_up.rb', line 66

def failure_message
  # last stage to have any candidate jobs
  failed_stage = @stages.reject do |s|
    s[:candidates].empty?
  end.last || @stages.first
  failed_matcher = failed_stage[:matcher]
  failed_candidates = failed_stage[:candidates]
  found_instead = failed_matcher.failed_msg(failed_candidates)

  "expected to enqueue #{job_description}, but found #{found_instead}"
end

#failure_message_when_negatedObject



78
79
80
81
82
# File 'lib/rspec/que/queue_up.rb', line 78

def failure_message_when_negated
  format "expected not to enqueue #{job_description}, got %d enqueued: %s",
         @matched_jobs.length,
         @matched_jobs.map { |j| format_job(j) }.join(", ")
end

#matches?(block) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rspec/que/queue_up.rb', line 29

def matches?(block)
  before_jobs = enqueued_jobs.dup
  block.call

  @matched_jobs = enqueued_jobs - before_jobs
  @matchers.each do |matcher|
    @stages << { matcher: matcher, candidates: @matched_jobs.dup }
    @matched_jobs.delete_if { |job| !matcher.matches?(job) }
  end

  @stages << { matcher: @count_matcher, candidates: @matched_jobs.dup }

  @count_matcher.matches?(@matched_jobs.count)
end

#of_priority(priority) ⇒ Object



54
55
56
57
# File 'lib/rspec/que/queue_up.rb', line 54

def of_priority(priority)
  @matchers << QueuedPriority.new(priority)
  self
end

#supports_block_expectations?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/rspec/que/queue_up.rb', line 84

def supports_block_expectations?
  true
end

#with(*args) ⇒ Object



44
45
46
47
# File 'lib/rspec/que/queue_up.rb', line 44

def with(*args)
  @matchers << QueuedArgs.new(args)
  self
end