Class: ConflowSpec::Matchers::RunJob

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/conflow_spec/matchers/run_job.rb

Overview

Specifies that flow should at some point enqueue specific job.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_class) ⇒ RunJob

Returns a new instance of RunJob.

Parameters:

  • job_class (Class)

    class of the worker expected to be run



12
13
14
15
# File 'lib/conflow_spec/matchers/run_job.rb', line 12

def initialize(job_class)
  @job_class = job_class
  @times = 1
end

Instance Attribute Details

#expected_paramsObject (readonly)

Returns the value of attribute expected_params.



9
10
11
# File 'lib/conflow_spec/matchers/run_job.rb', line 9

def expected_params
  @expected_params
end

#flowObject (readonly)

Returns the value of attribute flow.



9
10
11
# File 'lib/conflow_spec/matchers/run_job.rb', line 9

def flow
  @flow
end

#job_classObject (readonly)

Returns the value of attribute job_class.



9
10
11
# File 'lib/conflow_spec/matchers/run_job.rb', line 9

def job_class
  @job_class
end

Instance Method Details

#descriptionObject

Description of the spec



51
52
53
54
55
56
57
# File 'lib/conflow_spec/matchers/run_job.rb', line 51

def description
  [
    "run job #{job_class}",
    expected_params && "with parameters #{expected_params}",
    times_text(@times)
  ].compact.join(" ")
end

#failure_messageObject

Error message when matcher returns false, but it was expected to return true



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/conflow_spec/matchers/run_job.rb', line 69

def failure_message
  [
    "Expected flow to",
    description,
    "but",
    if relevant_jobs.size.zero?
      run_with_different_params? ? "it was not run with those parameters" : "it was not run at all"
    elsif relevant_jobs != @times
      "it was run #{times_text(relevant_jobs.size)}"
    end
  ].join(" ")
end

#failure_message_when_negatedObject

Error message when matcher returns true, but it was expected to return false



60
61
62
63
64
65
66
# File 'lib/conflow_spec/matchers/run_job.rb', line 60

def failure_message_when_negated
  [
    "Expected flow to not",
    description,
    "but it did"
  ].join(" ")
end

#matches?(flow) ⇒ Boolean

Returns true if all requirements are fulfilled.

Parameters:

  • flow (Conflow::Flow)

    flow instance which should enqueue job

Returns:

  • (Boolean)

    true if all requirements are fulfilled



19
20
21
22
23
# File 'lib/conflow_spec/matchers/run_job.rb', line 19

def matches?(flow)
  @flow = flow

  relevant_jobs.size == @times
end

#times(num) ⇒ Object

Specifies how many times job should be run

Examples:

expect(flow).to run_job(MyService).twice

Parameters:

  • num (Integer)

    number of times



45
46
47
48
# File 'lib/conflow_spec/matchers/run_job.rb', line 45

def times(num)
  @times = num
  self
end

#twiceObject

Convinience method to specify job should be enqueued twice

See Also:



36
37
38
39
# File 'lib/conflow_spec/matchers/run_job.rb', line 36

def twice
  @times = 2
  self
end

#with_params(params) ⇒ Object

Specifies parameters that the job should be run with.

Examples:

expect(flow).to run_job(MyService).with_params(id: 100)

Parameters:

  • params (Hash)

    hash of job params



29
30
31
32
# File 'lib/conflow_spec/matchers/run_job.rb', line 29

def with_params(params)
  @expected_params = params
  self
end