Sha256: 399428d37d6b0ffb5cec58857488264a145afedd3e63e111b62e7285d69a5861

Contents?: true

Size: 827 Bytes

Versions: 7

Compression:

Stored size: 827 Bytes

Contents

RSpec.describe Tram::Policy::ValidationError do
  subject(:error) { described_class.new policy, filter }

  let(:one)    { double message: "OMG!",  level: "error" }
  let(:two)    { double message: "phew!", level: "warning" }
  let(:policy) { double :policy, errors: [one, two] }

  shared_examples :exception_with_messages do |text|
    it { is_expected.to be_a RuntimeError }
    its(:policy)  { is_expected.to eq policy }
    its(:message) { is_expected.to eq "Validation failed with errors:#{text}" }
  end

  context "with a liberal filter" do
    let(:filter) { proc { false } }
    it_behaves_like :exception_with_messages, "\n- OMG!\n- phew!"
  end

  context "with a restricting filter" do
    let(:filter) { proc { |error| error.level != "error" } }
    it_behaves_like :exception_with_messages, "\n- OMG!"
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tram-policy-2.2.0 spec/tram/policy/validation_error_spec.rb
tram-policy-2.1.0 spec/tram/policy/validation_error_spec.rb
tram-policy-2.0.1 spec/tram/policy/validation_error_spec.rb
tram-policy-2.0.0 spec/tram/policy/validation_error_spec.rb
tram-policy-1.0.1 spec/tram/policy/validation_error_spec.rb
tram-policy-1.0.0 spec/tram/policy/validation_error_spec.rb
tram-policy-0.4.0 spec/tram/policy/validation_error_spec.rb