Sha256: 5a535bcd12aeaee9cb193498b4bfd706ecd2b81f8a73c1af60052160ab719edf

Contents?: true

Size: 1.35 KB

Versions: 22

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

describe Taskinator::TaskWorker do

  def mock_task(paused=false, cancelled=false, can_complete=false)
    double('task', :paused? => paused, :cancelled? => cancelled, :can_complete? => can_complete)
  end

  let(:uuid) { Taskinator.generate_uuid }

  subject { Taskinator::TaskWorker.new(uuid) }

  it "should fetch the task" do
    task = mock_task
    expect(Taskinator::Task).to receive(:fetch).with(uuid) { task }
    allow(task).to receive(:start!)
    subject.perform
  end

  it "should start the task" do
    task = mock_task
    allow(Taskinator::Task).to receive(:fetch).with(uuid) { task }
    expect(task).to receive(:start!)
    subject.perform
  end

  it "should not start if paused" do
    task = mock_task(true, false)
    allow(Taskinator::Task).to receive(:fetch).with(uuid) { task }
    expect(task).to_not receive(:start!)
    subject.perform
  end

  it "should not start if cancelled" do
    task = mock_task(false, true)
    allow(Taskinator::Task).to receive(:fetch).with(uuid) { task }
    expect(task).to_not receive(:start!)
    subject.perform
  end

  it "should fail if task raises an error" do
    task = mock_task
    allow(Taskinator::Task).to receive(:fetch).with(uuid) { task }
    allow(task).to receive(:start!) { raise StandardError }
    expect {
      subject.perform
    }.to raise_error(StandardError)
  end

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
taskinator-0.5.2 spec/taskinator/task_worker_spec.rb
taskinator-0.5.1 spec/taskinator/task_worker_spec.rb
taskinator-0.5.0 spec/taskinator/task_worker_spec.rb
taskinator-0.4.7 spec/taskinator/task_worker_spec.rb
taskinator-0.4.6 spec/taskinator/task_worker_spec.rb
taskinator-0.4.5 spec/taskinator/task_worker_spec.rb
taskinator-0.4.4 spec/taskinator/task_worker_spec.rb
taskinator-0.4.3 spec/taskinator/task_worker_spec.rb
taskinator-0.4.2 spec/taskinator/task_worker_spec.rb
taskinator-0.4.1 spec/taskinator/task_worker_spec.rb
taskinator-0.4.0 spec/taskinator/task_worker_spec.rb
taskinator-0.3.16 spec/taskinator/task_worker_spec.rb
taskinator-0.3.15 spec/taskinator/task_worker_spec.rb
taskinator-0.3.14 spec/taskinator/task_worker_spec.rb
taskinator-0.3.13 spec/taskinator/task_worker_spec.rb
taskinator-0.3.12 spec/taskinator/task_worker_spec.rb
taskinator-0.3.11 spec/taskinator/task_worker_spec.rb
taskinator-0.3.10 spec/taskinator/task_worker_spec.rb
taskinator-0.3.9 spec/taskinator/task_worker_spec.rb
taskinator-0.3.7 spec/taskinator/task_worker_spec.rb