Sha256: 81bd8526ad589b01700be0b9131eb23b4256a3ce71f44dc65fb7e8c4a18724cd

Contents?: true

Size: 1.78 KB

Versions: 2

Compression:

Stored size: 1.78 KB

Contents

require 'rspec'
require 'mercury/received_message'

describe Mercury::ReceivedMessage do

  describe '#ack' do
    it 'raises an error if the message is not actionable' do
      expect{make_non_actionable.ack}.to raise_error /not ackable/
    end
    it 'raises an error if an action was already taken' do
      msg = make_actionable
      msg.reject
      expect { msg.ack }.to raise_error /already rejected/
    end
  end

  describe '#nack' do
    it 'raises an error if the message is not actionable' do
      expect{make_non_actionable.nack}.to raise_error /not nackable/
    end
    it 'raises an error if an action was already taken' do
      msg = make_actionable
      msg.ack
      expect { msg.nack }.to raise_error /already acked/
    end
  end

  describe '#reject' do
    it 'raises an error if the message is not actionable' do
      expect{make_non_actionable.reject}.to raise_error /not rejectable/
    end
    it 'raises an error if an action was already taken' do
      msg = make_actionable
      msg.nack
      expect { msg.reject }.to raise_error /already nacked/
    end
  end

  describe '#action_taken' do
    it 'returns the action taken' do
      a = make_actionable
      expect(a.action_taken).to eql nil

      b = make_actionable
      b.ack
      expect(b.action_taken).to eql :ack

      c = make_actionable
      c.nack
      expect(c.action_taken).to eql :nack

      d = make_actionable
      d.reject
      expect(d.action_taken).to eql :reject
    end
  end

  def make_actionable
    Mercury::ReceivedMessage.new('hello', make_metadata, is_ackable: true)
  end

  def make_non_actionable
    Mercury::ReceivedMessage.new('hello', make_metadata, is_ackable: false)
  end

  def make_metadata
    m = double
    allow(m).to receive(:ack)
    allow(m).to receive(:reject)
    m
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercury_amqp-0.4.0 spec/lib/mercury/received_message_spec.rb
mercury_amqp-0.3.0 spec/lib/mercury/received_message_spec.rb