Module: ConflowSpec::Matchers

Defined in:
lib/conflow_spec/matchers.rb,
lib/conflow_spec/matchers/run_job.rb

Overview

Collection of matchers used to spec flows

Defined Under Namespace

Classes: RunJob

Instance Method Summary collapse

Instance Method Details

#run_job(job_class) ⇒ RunJob

Run job matchers checks if job of giben worker class is run in the flow.

Examples:

Verifying simple flow

class MyFlow < Conflow::Flow
  def configure(run_other: true)
    run RegularJob
    run OtherJob if run_other
  end
end

RSpec.describe MyFlow do
  subject { described_class.create(run_other: false) }

  it { is_expected.to run_job(RegularJob) }
  it { is_expected.to_not run_job(OtherJob) }
end

Specifying parameters

class MyFlow < Conflow::Flow
  def configure(id:)
    run UpdateJob, params: { id: id }
  end
end

RSpec.describe MyFlow do
  subject { described_class.create(id: 300) }

  it { is_expected.to run_job(UpdateJob).with_params(id: 300) }
  it { is_expected.to_not run_job(UpdateJob).with_params(id: 301) }
end

Specifying amounts

class MyFlow < Conflow::Flow
  def configure(ids:)
    ids.each { |id| run UpdateJob, params: { id: id } }
  end
end

RSpec.describe MyFlow do
  subject { described_class.create(ids: [300, 301]) }

  it { is_expected.to run_job(UpdateJob).twice } # or .times(2)
  it { is_expected.to run_job(UpdateJob).with_params(id: 300) }
  it { is_expected.to run_job(UpdateJob).with_params(id: 301) }
end

Parameters:

  • job_class (Class)

    Worker class that is (not) expected to run

Returns:

  • (RunJob)

    ] RSpec matcher



52
53
54
# File 'lib/conflow_spec/matchers.rb', line 52

def run_job(job_class)
  RunJob.new(job_class)
end