Sha256: 2397a49a2aca9864d203ecc64da0fbd2f89c64e793fe638d0d80ed84622b052a

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 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 "#delay_seconds" do

    it "is generated" do
      message = create_message({"DelaySeconds" => 10})
      expect(message.delay_seconds).to eq 10
    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

5 entries across 5 versions & 2 rubygems

Version Path
fake_servicebus-0.0.2 spec/unit/message_spec.rb
fake_sqs-0.4.3 spec/unit/message_spec.rb
fake_sqs-0.4.2 spec/unit/message_spec.rb
fake_sqs-0.4.1 spec/unit/message_spec.rb
fake_sqs-0.4.0 spec/unit/message_spec.rb