Skip to content
phstc edited this page Oct 8, 2014 · 10 revisions

Testing workers with RSpec

require 'spec_helper'

describe MyWorker do
  let(:sqs_msg) { double AWS::SQS::ReceivedMessage,
                  id: 'fc754df7-9cc2-4c41-96ca-5996a44b771e',
                  body: 'test',
                  delete: nil }

  describe '#perform' do
    it 'deletes the message' do
      expect(sqs_msg).to receive(:delete)

      subject.perform(sqs_msg)
    end

    it 'pushes a new message' do
      sqs_queue = double 'other queue'

      allow(Shoryuken::Client).to receive(:queues).
        with('other_queue').and_return(sqs_queue)

      expect(sqs_queue).to receive(:send_message).
        with('new test')

      subject.perform(sqs_msg)
    end
  end
end