Sha256: 1204a0a466f672662551853e76b4e234b774358a2831ec3ba6d49b460786dded

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

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

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

  describe "#item" do
    subject { error.item }
    it { is_expected.to eq [:bad, level: "warning", scope: scope] }
  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

1 entries across 1 versions & 1 rubygems

Version Path
tram-policy-2.2.0 spec/tram/policy/error_spec.rb