Sha256: 752c6d5ede70c0e86d17d66adaab516e6ad744e63ca7cb565854c64c9567bd8d

Contents?: true

Size: 1.47 KB

Versions: 13

Compression:

Stored size: 1.47 KB

Contents

RSpec.describe Tram::Policy::Error do
  subject(:error) { described_class.new "Something bad happened", tags }

  let(:tags) { { level: "warning" } }

  describe "#message" do
    subject { error.message }
    it { is_expected.to eq "Something bad happened" }
  end

  describe "#full_message" do
    subject { error.full_message }

    context "with tags:" do
      it { is_expected.to eq "Something bad happened {:level=>\"warning\"}" }
    end

    context "without tags:" do
      let(:tags) { {} }
      it { is_expected.to eq "Something bad happened" }
    end
  end

  describe "#to_h" do
    subject { error.to_h }
    it { is_expected.to eq message: "Something bad happened", level: "warning" }
  end

  describe "#==" do
    subject { error == other }

    context "when other object has the same #to_h:" do
      let(:other) { double to_h: error.to_h }
      it { is_expected.to eq true }
    end

    context "when other object has different #to_h:" do
      let(:other) { double to_h: error.to_h.merge(foo: :bar) }
      it { is_expected.to eq false }
    end

    context "when other object not respond to #to_h:" do
      let(:other) { double }
      it { is_expected.to eq false }
    end
  end

  describe "arbitrary tag" do
    subject { error.send tag }

    context "when tag is defined:" do
      let(:tag) { "level" }
      it { is_expected.to eq "warning" }
    end

    context "when tag not defined:" do
      let(:tag) { :weight }
      it { is_expected.to be_nil }
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
tram-policy-0.3.1 spec/tram/policy/error_spec.rb
tram-policy-0.3.0 spec/tram/policy/error_spec.rb
tram-policy-0.2.5 spec/tram/policy/error_spec.rb
tram-policy-0.2.4 spec/tram/policy/error_spec.rb
tram-policy-0.2.3 spec/tram/policy/error_spec.rb
tram-policy-0.2.2 spec/tram/policy/error_spec.rb
tram-policy-0.2.1 spec/tram/policy/error_spec.rb
tram-policy-0.2.0 spec/tram/policy/error_spec.rb
tram-policy-0.1.1 spec/tram/policy/error_spec.rb
tram-policy-0.1.0 spec/tram/policy/error_spec.rb
tram-policy-0.0.3 spec/tram/policy/error_spec.rb
tram-policy-0.0.2 spec/tram/policy/error_spec.rb
tram-policy-0.0.1 spec/tram/policy/error_spec.rb