Sha256: 0b4cee0f0ba00b564cdda604f1aac03477e1e6e3202e820e39531e0e11083d2f

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require 'fake_sqs/message'

RSpec.describe FakeSQS::Message do

  describe "#body" do

    it "is extracted from the MessageBody" do
      message = create_message("MessageBody" => "abc")
      expect(message.body).to eq "abc"
    end

  end

  describe "#md5" do

    it "is calculated from body" do
      message = create_message("MessageBody" => "abc")
      expect(message.md5).to eq "900150983cd24fb0d6963f7d28e17f72"
    end

  end

  describe "#id" do

    it "is generated" do
      message = create_message
      expect(message.id.size).to eq 36
    end

  end

  describe 'visibility_timeout' do

    let :message do
      create_message
    end

    it 'should default to nil' do
      expect(message.visibility_timeout).to eq nil
    end

    it 'should be expired when it is nil' do
      expect(message).to be_expired
    end

    it 'should be expired if set to a previous time' do
      message.visibility_timeout = Time.now - 1
      expect(message).to be_expired
    end

    it 'should not be expired at a future date' do
      message.visibility_timeout = Time.now + 1
      expect(message).not_to be_expired
    end

    it 'should not be expired when set to expire at a future date' do
      message.expire_at(5)
      expect(message.visibility_timeout).to be >=(Time.now + 4)
    end

  end

  def create_message(options = {})
    FakeSQS::Message.new({"MessageBody" => "test"}.merge(options))
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fake_sqs-0.3.1 spec/unit/message_spec.rb
fake_sqs-0.3.0 spec/unit/message_spec.rb
fake_sqs-0.2.0 spec/unit/message_spec.rb