Update code and specs to use new names of predicates

This commit is contained in:
Nikita Shilnikov 2022-10-30 21:18:26 +03:00
parent d5c65d2375
commit 45cca256f9
No known key found for this signature in database
GPG Key ID: E569D1D64C40E241
13 changed files with 44 additions and 43 deletions

View File

@ -20,6 +20,8 @@ en:
eql?: "must be equal to %{left}"
is_eql?: "must be equal to %{left}"
not_eql?: "must not be equal to %{left}"
filled?: "must be filled"
@ -89,6 +91,8 @@ en:
respond_to?: "must respond to %{method}"
interface?: "must respond to %{method}"
size?:
arg:
default: "size must be %{size}"

View File

@ -38,7 +38,7 @@ Checks that a key's value is equal to the given value.
describe 'eql?' do
let(:schema) do
Dry::Schema.Params do
required(:sample).value(eql?: 1234)
required(:sample).value(is_eql?: 1234)
end
end

View File

@ -71,7 +71,7 @@ module Dry
# @api private
def ensure_valid
if compiler.predicates[name].arity - 1 != args.size
if compiler.predicates[name].arity - 1 != args.size && !name.eql?(:eql?)
raise ArgumentError, "#{name} predicate arity is invalid"
end
end

View File

@ -1,8 +1,5 @@
# frozen_string_literal: true
require "dry/container"
require "dry/types"
module Dry
module Schema
# A class to build containers for custom types, which can be used in schemas
@ -13,9 +10,9 @@ module Dry
#
# @api public
class TypeContainer
include Dry::Container::Mixin
include Core::Container::Mixin
def initialize(types_container = Dry::Types.container)
def initialize(types_container = ::Dry::Types.container)
super()
merge(types_container)

View File

@ -1,6 +1,6 @@
en:
dry_schema:
errors:
eql?:
is_eql?:
failure: '%{right} is not equal to blue'
hint: 'must be equal to blue'

View File

@ -70,10 +70,10 @@ RSpec.describe "Validation hints" do
context "with a nested schema with same rule names" do
subject(:schema) do
Dry::Schema.define do
required(:code).filled(:str?, eql?: "foo")
required(:code).filled(:str?, is_eql?: "foo")
required(:nested).hash do
required(:code).filled(:str?, eql?: "bar")
required(:code).filled(:str?, is_eql?: "bar")
end
end
end
@ -150,7 +150,7 @@ RSpec.describe "Validation hints" do
Dry::Schema.define do
configure { |c| c.messages.load_paths << SPEC_ROOT.join("fixtures/messages.yml") }
required(:pill).filled(eql?: "blue")
required(:pill).filled(is_eql?: "blue")
end
end

View File

@ -406,10 +406,10 @@ RSpec.describe Dry::Schema::MessageCompiler do
end
end
describe ":eql?" do
describe ":is_eql?" do
it "returns valid message" do
msg = message_compiler.visit(
[:failure, [:str, [:key, [:str, p(:eql?, "Bar", "Foo")]]]]
[:failure, [:str, [:key, [:str, p(:is_eql?, "Bar", "Foo")]]]]
)
expect(msg).to eql("must be equal to Bar")

View File

@ -4,7 +4,7 @@ RSpec.describe "Predicates: Eql" do
context "with required" do
subject(:schema) do
Dry::Schema.Params do
required(:foo).value(:string) { eql?("23") }
required(:foo).value(:string) { is_eql?("23") }
end
end
@ -86,7 +86,7 @@ RSpec.describe "Predicates: Eql" do
context "with value" do
subject(:schema) do
Dry::Schema.Params do
required(:foo).value(:string, eql?: "23")
required(:foo).value(:string, is_eql?: "23")
end
end
@ -166,7 +166,7 @@ RSpec.describe "Predicates: Eql" do
context "with maybe" do
subject(:schema) do
Dry::Schema.Params do
required(:foo).maybe(:string, eql?: "23")
required(:foo).maybe(:string, is_eql?: "23")
end
end
@ -248,7 +248,7 @@ RSpec.describe "Predicates: Eql" do
context "with filled" do
subject(:schema) do
Dry::Schema.Params do
optional(:foo).filled(:string, eql?: "23")
optional(:foo).filled(:string, is_eql?: "23")
end
end

View File

@ -46,7 +46,7 @@ RSpec.describe "Registering custom types" do
end
it "raises exception that nothing is registered with the key" do
expect { result }.to raise_exception(Dry::Container::KeyError)
expect { result }.to raise_exception(Dry::Core::Container::KeyError)
end
end
@ -123,7 +123,7 @@ RSpec.describe "Registering custom types" do
end
it "raises exception that nothing is registered with the key" do
expect { result }.to raise_exception(Dry::Container::KeyError)
expect { result }.to raise_exception(Dry::Core::Container::KeyError)
end
end

View File

@ -4,7 +4,7 @@ RSpec.describe "Predicates: Eql" do
context "with required" do
subject(:schema) do
Dry::Schema.define do
required(:foo) { eql?(23) }
required(:foo) { is_eql?(23) }
end
end
@ -44,7 +44,7 @@ RSpec.describe "Predicates: Eql" do
context "with optional" do
subject(:schema) do
Dry::Schema.define do
optional(:foo) { eql?(23) }
optional(:foo) { is_eql?(23) }
end
end
@ -86,7 +86,7 @@ RSpec.describe "Predicates: Eql" do
context "with value" do
subject(:schema) do
Dry::Schema.define do
required(:foo).value(eql?: 23)
required(:foo).value(is_eql?: 23)
end
end
@ -126,7 +126,7 @@ RSpec.describe "Predicates: Eql" do
context "with filled" do
subject(:schema) do
Dry::Schema.define do
required(:foo).filled(eql?: 23)
required(:foo).filled(is_eql?: 23)
end
end
@ -166,7 +166,7 @@ RSpec.describe "Predicates: Eql" do
context "with maybe" do
subject(:schema) do
Dry::Schema.define do
required(:foo).maybe(eql?: 23)
required(:foo).maybe(is_eql?: 23)
end
end
@ -208,7 +208,7 @@ RSpec.describe "Predicates: Eql" do
context "with value" do
subject(:schema) do
Dry::Schema.define do
optional(:foo).value(eql?: 23)
optional(:foo).value(is_eql?: 23)
end
end
@ -248,7 +248,7 @@ RSpec.describe "Predicates: Eql" do
context "with filled" do
subject(:schema) do
Dry::Schema.define do
optional(:foo).filled(eql?: 23)
optional(:foo).filled(is_eql?: 23)
end
end
@ -288,7 +288,7 @@ RSpec.describe "Predicates: Eql" do
context "with maybe" do
subject(:schema) do
Dry::Schema.define do
optional(:foo).maybe(eql?: 23)
optional(:foo).maybe(is_eql?: 23)
end
end

View File

@ -97,7 +97,7 @@ RSpec.describe "Predicates: Respond To" do
context "with required" do
context "with value" do
subject(:schema) do
Dry::Schema.define { required(:foo).value(respond_to?: :bar) }
Dry::Schema.define { required(:foo).value(interface?: :bar) }
end
context "with valid input" do
@ -143,7 +143,7 @@ RSpec.describe "Predicates: Respond To" do
context "with filled" do
subject(:schema) do
Dry::Schema.define { required(:foo).filled(respond_to?: :bar) }
Dry::Schema.define { required(:foo).filled(interface?: :bar) }
end
context "with valid input" do
@ -189,7 +189,7 @@ RSpec.describe "Predicates: Respond To" do
context "with maybe" do
subject(:schema) do
Dry::Schema.define { required(:foo).maybe(respond_to?: :bar) }
Dry::Schema.define { required(:foo).maybe(interface?: :bar) }
end
context "with valid input" do
@ -237,7 +237,7 @@ RSpec.describe "Predicates: Respond To" do
context "with optional" do
context "with value" do
subject(:schema) do
Dry::Schema.define { optional(:foo).value(respond_to?: :bar) }
Dry::Schema.define { optional(:foo).value(interface?: :bar) }
end
context "with valid input" do
@ -283,7 +283,7 @@ RSpec.describe "Predicates: Respond To" do
context "with filled" do
subject(:schema) do
Dry::Schema.define { optional(:foo).filled(respond_to?: :bar) }
Dry::Schema.define { optional(:foo).filled(interface?: :bar) }
end
context "with valid input" do
@ -329,7 +329,7 @@ RSpec.describe "Predicates: Respond To" do
context "with maybe" do
subject(:schema) do
Dry::Schema.define { optional(:foo).maybe(respond_to?: :bar) }
Dry::Schema.define { optional(:foo).maybe(interface?: :bar) }
end
context "with valid input" do

View File

@ -50,25 +50,25 @@ RSpec.describe "inheriting from a parent and extending its rules" do
end
required(:qux).hash do
required(:hello).hash do
required(:wow).value(:string, eql?: "a")
required(:such).value(:string, eql?: "cool")
required(:wow).value(:string, is_eql?: "a")
required(:such).value(:string, is_eql?: "cool")
required(:amaze).value(array[:string], size?: 1)
end
required(:my).hash do
required(:wow).value(:string, eql?: "b")
required(:such).value(:string, eql?: "cool")
required(:wow).value(:string, is_eql?: "b")
required(:such).value(:string, is_eql?: "cool")
required(:amaze).value(array[:string], size?: 1)
end
required(:friend).hash do
required(:wow).filled(:string, eql?: "c")
required(:such).filled(:string, eql?: "cool")
required(:wow).filled(:string, is_eql?: "c")
required(:such).filled(:string, is_eql?: "cool")
required(:amaze).value(array[:string], size?: 1)
end
end
end
required(:last).filled.hash do
required(:not).value(:array, eql?: ["rad"])
required(:least).value(:string, eql?: "done")
required(:not).value(:array, is_eql?: ["rad"])
required(:least).value(:string, is_eql?: "done")
end
end
end

View File

@ -13,7 +13,7 @@ RSpec.describe Dry::Schema::Trace do
end
it "stores evaluated predicates with args" do
trace.evaluate(eql?: "foo")
trace.evaluate(is_eql?: "foo")
expect(trace.captures).to include(trace.eql?("foo"))
end
@ -23,7 +23,7 @@ RSpec.describe Dry::Schema::Trace do
it "creates predicate objects" do
predicate = trace.eql?("foo")
expect(predicate.name).to be(:eql?)
expect(predicate.name).to be(:is_eql?)
expect(predicate.args).to eql(["foo"])
end