spec/tram/policy/errors_spec.rb in tram-policy-1.0.1 vs spec/tram/policy/errors_spec.rb in tram-policy-2.0.0
- old
+ new
@@ -1,16 +1,16 @@
RSpec.describe Tram::Policy::Errors do
- let(:policy) { double :policy, scope: %w[tram-policy] }
- let(:errors) { described_class.new(policy) }
+ let(:scope) { %w[tram-policy] }
+ let(:errors) { described_class.new(scope: scope) }
describe ".new" do
subject { errors }
it { is_expected.to be_kind_of Enumerable }
it { is_expected.to respond_to :empty? }
it { is_expected.to be_empty }
- its(:policy) { is_expected.to eql policy }
+ its(:scope) { is_expected.to eql scope }
end
describe "#add" do
subject { errors.add :omg, level: "info", field: "name" }
@@ -19,11 +19,11 @@
it "adds an error to the collection:" do
expect { 2.times { subject } }.to change { errors.count }.by 1
expect(error).to be_kind_of Tram::Policy::Error
expect(error)
- .to eq [:omg, level: "info", field: "name", scope: %w[tram-policy]]
+ .to eq [:omg, level: "info", field: "name", scope: scope]
end
end
describe "#empty?" do
subject { errors.add :omg, level: "info", field: "name" }
@@ -43,61 +43,61 @@
before { errors.add "OMG!", level: "info", field: "name" }
it { is_expected.to eq errors.map(&:item) }
end
describe "#merge" do
- let(:other) { described_class.new(policy) }
+ let(:other) { described_class.new(scope: scope) }
before do
- errors.add "D'OH!", level: "disaster"
- other.add "OUCH!", level: "error"
+ errors.add :"D'OH!", level: "disaster"
+ other.add "OUCH!", level: "error"
end
context "without a block:" do
subject { errors.merge(other) }
it "merges other collection as is" do
expect(subject).to be_a Tram::Policy::Errors
expect(subject.items).to match_array [
- ["D'OH!", level: "disaster", scope: %w[tram-policy]],
- ["OUCH!", level: "error", scope: %w[tram-policy]]
+ [:"D'OH!", level: "disaster", scope: scope],
+ ["OUCH!", level: "error"]
]
end
end
context "with a block:" do
subject { errors.merge(other) { |err| err.merge(source: "Homer") } }
it "merges filtered collection as is" do
expect(subject).to be_a Tram::Policy::Errors
expect(subject.items).to match_array [
- ["D'OH!", level: "disaster", scope: %w[tram-policy]],
- ["OUCH!", level: "error", scope: %w[tram-policy], source: "Homer"]
+ [:"D'OH!", level: "disaster", scope: scope],
+ ["OUCH!", level: "error", source: "Homer"]
]
end
end
context "with options:" do
subject { errors.merge(other, source: "Homer") }
it "merges other collection with given options" do
expect(subject).to be_a Tram::Policy::Errors
expect(subject.items).to match_array [
- ["D'OH!", level: "disaster", scope: %w[tram-policy]],
- ["OUCH!", level: "error", scope: %w[tram-policy], source: "Homer"]
+ [:"D'OH!", level: "disaster", scope: scope],
+ ["OUCH!", level: "error", source: "Homer"]
]
end
end
context "with block and options:" do
subject { errors.merge(other, id: 5) { |err| err.merge id: 3, age: 4 } }
it "merges filtered collection with given options" do
expect(subject).to be_a Tram::Policy::Errors
expect(subject.items).to match_array [
- ["D'OH!", level: "disaster", scope: %w[tram-policy]],
- ["OUCH!", level: "error", scope: %w[tram-policy], id: 5, age: 4]
+ [:"D'OH!", level: "disaster", scope: scope],
+ ["OUCH!", level: "error", id: 5, age: 4]
]
end
end
context "with no errors:" do
@@ -123,11 +123,11 @@
context "with filter" do
subject { errors.filter level: "error" }
it "returns selected errors only" do
expect(subject).to match_array [
- [:foo, field: "name", level: "error", scope: %w[tram-policy]],
- [:foo, field: "email", level: "error", scope: %w[tram-policy]]
+ [:foo, field: "name", level: "error", scope: scope],
+ [:foo, field: "email", level: "error", scope: scope]
]
end
end
context "without a filter" do