Sha256: 00f8829613ed15af1ea250e13ceb98a56c9433bcba4fdfe397a52f058bbe75ac

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

RSpec.describe Tram::Policy::Error do
  subject(:error) { described_class.new :bad, options }

  let(:options) { { level: "warning", scope: %w[tram-policy] } }

  describe "#item" do
    subject { error.item }
    it { is_expected.to eq [:bad, level: "warning", scope: %w[tram-policy]] }
  end

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

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

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

    context "when other object has different #item:" do
      let(:other) { double to_a: [:foo] }
      it { is_expected.to eq false }
    end

    context "when other object not respond to #item:" 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

3 entries across 3 versions & 1 rubygems

Version Path
tram-policy-1.0.1 spec/tram/policy/error_spec.rb
tram-policy-1.0.0 spec/tram/policy/error_spec.rb
tram-policy-0.4.0 spec/tram/policy/error_spec.rb