Module: LittleMonster::RSpec::JobHelper
- Defined in:
- lib/little_monster/rspec/helpers/job_helper.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
Instance Method Details
#generate_job(job, options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/little_monster/rspec/helpers/job_helper.rb', line 44 def generate_job(job, = {}) job_class = job.class == Class ? job : job.to_s.camelcase.constantize job_class.mock! job_instance = job_class.new(data: { outputs: .fetch(:data, {}) }) job_instance.define_singleton_method(:is_cancelled?) { .fetch(:cancelled, false) } if [:fails] [:fails] = [[:fails]] unless [:fails].is_a? Array [: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 |