module LittleMonster::RSpec::JobHelper

Public Instance Methods

generate_job(job, options = {}) click to toggle source
# File lib/little_monster/rspec/helpers/job_helper.rb, line 44
def generate_job(job, options = {})
  job_class = job.class == Class ? job : job.to_s.camelcase.constantize
  job_class.mock!

  job_instance = job_class.new(data: { outputs: options.fetch(:data, {}) })
  job_instance.define_singleton_method(:is_cancelled?) { options.fetch(:cancelled, false) }

  if options[:fails]
    options[:fails] = [options[:fails]] unless options[:fails].is_a? Array
    options[:fails].each do |hash|
      allow_any_instance_of(job_class.task_class_for(hash[:task])).to receive(:run).and_raise(hash.fetch(:error, StandardError.new))
    end
  end

  job_instance
end
run_job(job, options = {}) click to toggle source
# File lib/little_monster/rspec/helpers/job_helper.rb, line 40
def run_job(job, options = {})
  Result.new(generate_job(job, options))
end