Sha256: 05cb6faa4ce0dfef8e3c32fb91e1d3936c58aaa89023c940e043a7eced5ca363

Contents?: true

Size: 1.9 KB

Versions: 3

Compression:

Stored size: 1.9 KB

Contents

require "spec_helper"

module Hexx
  describe Message do

    describe ".new" do

      subject { Message }

      it "requires type" do
        expect { subject.new text: "" }.to raise_error
      end

      it "requires text" do
        expect { subject.new type: "" }.to raise_error
      end
    end

    describe "#type" do

      subject { Message.new type: "info", text: "text" }

      it "returns message type" do
        expect(subject.type).to eq "info"
      end
    end

    describe "#text" do

      subject { Message.new type: "info", text: "text" }

      it "returns message text" do
        expect(subject.text).to eq "text"
      end
    end

    describe "#==" do

      let!(:params) { { type: "info", text: "text" } }

      it "returns true if type and text of two messages are the same" do
        expect(Message.new params).to eq(Message.new params)
      end

      it "returns false if types of two messages are different" do
        expect(Message.new params)
          .not_to eq(Message.new params.merge(type: "error"))
      end

      it "returns false if texts of two messages are different" do
        expect(Message.new params)
          .not_to eq(Message.new params.merge(text: "another"))
      end

      it "returns false when a message compares to non-message" do
        expect(Message.new params).not_to eq("text")
      end
    end

    describe "#<=>" do

      let!(:aa) { Message.new type: "a", text: "a" }
      let!(:ab) { Message.new type: "a", text: "b" }
      let!(:ba) { Message.new type: "b", text: "a" }

      it "orders messages by type" do
        expect(aa < ba).to be_truthy
      end

      it "orders messages by text" do
        expect(aa < ab).to be_truthy
      end

      it "orders messages first by type" do
        expect(ab < ba).to be_truthy
      end

      it "fails when compared with non-message" do
        expect { ab < "" }.to raise_error
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hexx-7.1.0 spec/hexx/message_spec.rb
hexx-7.0.1 spec/hexx/message_spec.rb
hexx-7.0.0 spec/hexx/message_spec.rb