Sha256: 43b28c3314140738c1a3cec7a4c957ebfafffe11f5ccb695a9372ac026f05102

Contents?: true

Size: 1.88 KB

Versions: 5

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'

describe DispatchRider::Message do
  subject(:message) {DispatchRider::Message.new(:subject => 'test', :body => 'test_handler')}

  describe "#initialize" do
    context "when all the required attributes are passed" do
      context "when the attributes hash has keys as strings" do
        subject(:message) {DispatchRider::Message.new('subject' => 'test', 'body' => 'test_handler')}

        it "should initiate a new message" do
          message.subject.should eq('test')
          message.body.should eq('test_handler')
        end
      end

      context "when the attributes hash has keys as symbols" do
        it "should initiate a new message" do
          message.subject.should eq('test')
          message.body.should eq('test_handler')
        end
      end
    end

    context "when all the required attributes are not passed" do
      it "should raise an exception" do
        expect { DispatchRider::Message.new({}) }.to raise_exception(DispatchRider::RecordInvalid)
      end
    end
  end

  describe "#attributes" do
    it "should return the attributes hash of the message" do
      message.attributes.should eq({:subject => 'test', :body => 'test_handler'})
    end
  end

  describe "#to_json" do
    it "should return the attributes hash in json format" do
      result = JSON.parse(message.to_json)
      result['subject'].should eq('test')
      result['body'].should eq('test_handler')
    end
  end

  describe "#==" do
    context "when 2 messages have the same attribute values" do
      it "should return true" do
        message.should eq(DispatchRider::Message.new(:subject => 'test', :body => 'test_handler'))
      end
    end

    context "when 2 messages do not have same attribute values" do
      it "should return false" do
        message.should_not eq(DispatchRider::Message.new(:subject => 'random_test', :body => 'test_handler'))
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dispatch-rider-1.5.3 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.5.2 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.5.1 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.5.0 spec/lib/dispatch-rider/message_spec.rb
dispatch-rider-1.4.2 spec/lib/dispatch-rider/message_spec.rb