Projects
Mega:23.09
rubygem-contracts
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 3
View file
_service:tar_scm:rubygem-contracts.spec
Changed
@@ -1,17 +1,11 @@ %global gem_name contracts Name: rubygem-%{gem_name} -Version: 0.16.0 -Release: 4 +Version: 0.17 +Release: 1 Summary: Contracts for Ruby License: BSD-2-Clause URL: http://egonschiele.github.io/contracts.ruby/ Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem -Patch1: rubygem-contracts-0.16.0-0001-Don-t-use-exceptions-for-control-flow.patch -Patch2: rubygem-contracts-0.16.0-0002-Update-spec-to-specify-error-class-to-suppress-RSpec.patch -Patch3: rubygem-contracts-0.16.0-0003-Fix-misspellings-in-comments.patch -Patch4: rubygem-contracts-0.16.0-0004-Wrapping-blocks-only-when-there-is-a-Func-check.-bug.patch -Patch5: rubygem-contracts-0.16.0-0005-Update-implementation-spec-to-be-3.0-compatible.patch -Patch6: rubygem-contracts-0.16.0-0006-Remove-deprecated-const-fixnum.patch BuildRequires: ruby(release) rubygems-devel ruby rubygem(rspec) >= 3 BuildArch: noarch %description @@ -27,18 +21,13 @@ Documentation for %{name}. %prep -gem unpack %{SOURCE0} -%setup -q -D -T -n %{gem_name}-%{version} - -%patch1 -p1 -%patch2 -p1 -%patch3 -p1 -%patch4 -p1 -%patch5 -p1 -%patch6 -p1 - +%setup -q -n %{gem_name}-%{version} gem spec %{SOURCE0} -l --ruby > %{gem_name}.gemspec +# Ruby3.2 removes Fixnum +# https://github.com/egonSchiele/contracts.ruby/issues/300 +sed -i spec/fixtures/fixtures.rb -e 's|Fixnum|Integer|' + %build gem build %{gem_name}.gemspec %gem_install @@ -80,6 +69,9 @@ %{gem_instdir}/benchmarks/ %changelog +* Mon Nov 13 2023 wangkai <13474090681@163.com> - 0.17-1 +- Update to 0.17 + * Wed Aug 02 2023 Ge Wang <wang__ge@126.com> - 0.16.0-4 - Remove deprecated const fixnum due to ruby updated
View file
_service:tar_scm:rubygem-contracts-0.16.0-0001-Don-t-use-exceptions-for-control-flow.patch
Deleted
@@ -1,102 +0,0 @@ -From 726e28c473b8d4453b4485922a2c52e9511bfc42 Mon Sep 17 00:00:00 2001 -From: Chris Seaton <chris@chrisseaton.com> -Date: Fri, 10 Nov 2017 17:20:38 +0000 -Subject: PATCH 1/5 Don't use exceptions for control flow - ---- - lib/contracts/call_with.rb | 22 +++++++++++++-------- - lib/contracts/method_handler.rb | 34 +++++++++++++-------------------- - 2 files changed, 27 insertions(+), 29 deletions(-) - -diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb -index c8a8b62..2735d1e 100644 ---- a/lib/contracts/call_with.rb -+++ b/lib/contracts/call_with.rb -@@ -1,6 +1,10 @@ - module Contracts - module CallWith - def call_with(this, *args, &blk) -+ call_with_inner(false, this, *args, &blk) -+ end -+ -+ def call_with_inner(returns, this, *args, &blk) - args << blk if blk - - # Explicitly append blk=nil if nil != Proc contract violation anticipated -@@ -16,14 +20,16 @@ module Contracts - validator = @args_validatorsi - - unless validator && validatorarg -- return unless Contract.failure_callback(:arg => arg, -- :contract => contract, -- :class => klass, -- :method => method, -- :contracts => self, -- :arg_pos => i+1, -- :total_args => args.size, -- :return_value => false) -+ data = {:arg => arg, -+ :contract => contract, -+ :class => klass, -+ :method => method, -+ :contracts => self, -+ :arg_pos => i+1, -+ :total_args => args.size, -+ :return_value => false} -+ return ParamContractError.new("as return value", data) if returns -+ return unless Contract.failure_callback(data) - end - - if contract.is_a?(Contracts::Func) && blk && !nil_block_appended -diff --git a/lib/contracts/method_handler.rb b/lib/contracts/method_handler.rb -index ee16b6b..fe301cd 100644 ---- a/lib/contracts/method_handler.rb -+++ b/lib/contracts/method_handler.rb -@@ -125,31 +125,23 @@ module Contracts - # function. Otherwise we return the result. - # If we run out of functions, we raise the last error, but - # convert it to_contract_error. -- success = false -- i = 0 -- result = nil -+ - expected_error = decorated_methods0.failure_exception -+ last_error = nil - -- until success -- decorated_method = decorated_methodsi -- i += 1 -- begin -- success = true -- result = decorated_method.call_with(self, *args, &blk) -- rescue expected_error => error -- success = false -- unless decorated_methodsi -- begin -- ::Contract.failure_callback(error.data, false) -- rescue expected_error => final_error -- raise final_error.to_contract_error -- end -- end -- end -+ decorated_methods.each do |decorated_method| -+ result = decorated_method.call_with_inner(true, self, *args, &blk) -+ return result unless result.is_a?(ParamContractError) -+ last_error = result - end - -- # Return the result of successfully called method -- result -+ begin -+ if ::Contract.failure_callback(last_error.data, false) -+ decorated_methods.last.call_with_inner(false, self, *args, &blk) -+ end -+ rescue expected_error => final_error -+ raise final_error.to_contract_error -+ end - end - end - --- -2.29.2 -
View file
_service:tar_scm:rubygem-contracts-0.16.0-0002-Update-spec-to-specify-error-class-to-suppress-RSpec.patch
Deleted
@@ -1,73 +0,0 @@ -From 85c6a4e471f2013079dc5a63c1a6bb84bee9351b Mon Sep 17 00:00:00 2001 -From: PikachuEXE <pikachuexe@gmail.com> -Date: Mon, 25 Jan 2021 17:26:45 +0800 -Subject: PATCH 2/5 * Update spec to specify error class to suppress RSpec - warning - ---- - spec/contracts_spec.rb | 6 +++--- - spec/methods_spec.rb | 8 ++++---- - 2 files changed, 7 insertions(+), 7 deletions(-) - -diff --git a/spec/contracts_spec.rb b/spec/contracts_spec.rb -index d37c40e..72c8603 100644 ---- a/spec/contracts_spec.rb -+++ b/spec/contracts_spec.rb -@@ -7,7 +7,7 @@ RSpec.describe "Contracts:" do - it "should fail for insufficient arguments" do - expect do - @o.hello -- end.to raise_error -+ end.to raise_error ArgumentError - end - - it "should fail for insufficient contracts" do -@@ -32,7 +32,7 @@ RSpec.describe "Contracts:" do - 1 - end - end -- end.to raise_error -+ end.to raise_error NameError - end - end - -@@ -696,7 +696,7 @@ RSpec.describe "Contracts:" do - it "should apply the contract to an inherited method" do - c = Child.new - expect { c.double(2) }.to_not raise_error -- expect { c.double("asd") }.to raise_error -+ expect { c.double("asd") }.to raise_error ParamContractError - end - end - -diff --git a/spec/methods_spec.rb b/spec/methods_spec.rb -index 334fb4e..d1b5d47 100644 ---- a/spec/methods_spec.rb -+++ b/spec/methods_spec.rb -@@ -36,19 +36,19 @@ RSpec.describe "Contracts:" do - end - - it "should enforce return value inside block with no other parameter" do -- expect { obj.foo(&:to_s) }.to raise_error -+ expect { obj.foo(&:to_s) }.to raise_error ReturnContractError - end - - it "should enforce return value inside block with other parameter" do -- expect { obj.foo2(2) { |x| x.to_s } }.to raise_error -+ expect { obj.foo2(2) { |x| x.to_s } }.to raise_error ReturnContractError - end - - it "should enforce return value inside lambda with no other parameter" do -- expect { obj.bar lambda { |x| x.to_s } }.to raise_error -+ expect { obj.bar lambda { |x| x.to_s } }.to raise_error ReturnContractError - end - - it "should enforce return value inside lambda with other parameter" do -- expect { obj.bar2(2, lambda { |x| x.to_s }) }.to raise_error -+ expect { obj.bar2(2, lambda { |x| x.to_s }) }.to raise_error ReturnContractError - end - end - end --- -2.29.2 -
View file
_service:tar_scm:rubygem-contracts-0.16.0-0003-Fix-misspellings-in-comments.patch
Deleted
@@ -1,40 +0,0 @@ -From 989ee11906bb2061b2618bd1d8f128162e143a79 Mon Sep 17 00:00:00 2001 -From: Olle Jonsson <olle.jonsson@gmail.com> -Date: Sun, 24 Sep 2017 19:08:58 +0200 -Subject: PATCH 3/5 Fix misspellings in comments - - - found using find . | misspellings -f - ---- - lib/contracts/call_with.rb | 2 +- - spec/ruby_version_specific/contracts_spec_2.1.rb | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb -index 2735d1e..c9336a1 100644 ---- a/lib/contracts/call_with.rb -+++ b/lib/contracts/call_with.rb -@@ -80,7 +80,7 @@ module Contracts - # proc, block, lambda, etc - method.call(*args, &blk) - else -- # original method name referrence -+ # original method name reference - added_block = blk ? lambda { |*params| blk.call(*params) } : nil - method.send_to(this, *args, &added_block) - end -diff --git a/spec/ruby_version_specific/contracts_spec_2.1.rb b/spec/ruby_version_specific/contracts_spec_2.1.rb -index 168cfd0..36b6ede 100644 ---- a/spec/ruby_version_specific/contracts_spec_2.1.rb -+++ b/spec/ruby_version_specific/contracts_spec_2.1.rb -@@ -51,7 +51,7 @@ RSpec.describe "Contracts:" do - end.to raise_error(ContractError) - end - -- it "should fail when passed nil to an optional argument which contract shouldnt accept nil" do -+ it "should fail when passed nil to an optional argument which contract shouldn't accept nil" do - expect do - @o.complicated("a", true, :b, :c, 2.0, e: (1..5), f: nil, g: :d) do |x| - x --- -2.29.2 -
View file
_service:tar_scm:rubygem-contracts-0.16.0-0004-Wrapping-blocks-only-when-there-is-a-Func-check.-bug.patch
Deleted
@@ -1,30 +0,0 @@ -From ab30dab081c4e004812eab00a36c70e5b8e4e29b Mon Sep 17 00:00:00 2001 -From: md-work <> -Date: Thu, 14 Dec 2017 11:37:18 +0100 -Subject: PATCH 4/5 Wrapping &blocks only when there is a Func check. (bug - 278) - ---- - lib/contracts/call_with.rb | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb -index c9336a1..9252c79 100644 ---- a/lib/contracts/call_with.rb -+++ b/lib/contracts/call_with.rb -@@ -81,8 +81,10 @@ module Contracts - method.call(*args, &blk) - else - # original method name reference -- added_block = blk ? lambda { |*params| blk.call(*params) } : nil -- method.send_to(this, *args, &added_block) -+ # Don't reassign blk, else Travis CI shows "stack level too deep". -+ target_blk = blk -+ target_blk = lambda { |*params| blk.call(*params) } if blk && blk.is_a?(Contract) -+ method.send_to(this, *args, &target_blk) - end - - unless @ret_validatorresult --- -2.29.2 -
View file
_service:tar_scm:rubygem-contracts-0.16.0-0005-Update-implementation-spec-to-be-3.0-compatible.patch
Deleted
@@ -1,387 +0,0 @@ -From 62ad3fb999287f1495273d4ef41ff6abc28fd278 Mon Sep 17 00:00:00 2001 -From: PikachuEXE <pikachuexe@gmail.com> -Date: Tue, 26 Jan 2021 17:37:59 +0800 -Subject: PATCH 5/5 * Update implementation & spec to be 3.0 compatible - -Mainly around the breaking behaviour change about keyword arguments ---- - lib/contracts.rb | 14 ++++----- - lib/contracts/call_with.rb | 31 ++++++++++--------- - lib/contracts/invariants.rb | 10 +++--- - lib/contracts/method_handler.rb | 6 ++-- - lib/contracts/method_reference.rb | 4 +-- - spec/builtin_contracts_spec.rb | 20 +++++------- - spec/contracts_spec.rb | 21 +++++++------ - spec/fixtures/fixtures.rb | 9 ++---- - spec/override_validators_spec.rb | 6 ++-- - .../contracts_spec_2.0.rb | 4 +-- - spec/validators_spec.rb | 2 +- - 11 files changed, 63 insertions(+), 64 deletions(-) - -diff --git a/lib/contracts.rb b/lib/contracts.rb -index baf2acf..f5ae75d 100644 ---- a/lib/contracts.rb -+++ b/lib/contracts.rb -@@ -93,9 +93,9 @@ class Contract < Contracts::Decorator - last_contract = args_contracts.last - penultimate_contract = args_contracts-2 - @has_options_contract = if @has_proc_contract -- penultimate_contract.is_a?(Hash) || penultimate_contract.is_a?(Contracts::Builtin::KeywordArgs) -+ penultimate_contract.is_a?(Contracts::Builtin::KeywordArgs) - else -- last_contract.is_a?(Hash) || last_contract.is_a?(Contracts::Builtin::KeywordArgs) -+ last_contract.is_a?(Contracts::Builtin::KeywordArgs) - end - # === - -@@ -214,12 +214,12 @@ class Contract < Contracts::Decorator - - # Same thing for when we have named params but didn't pass any in. - # returns true if it appended nil -- def maybe_append_options! args, blk -+ def maybe_append_options! args, kargs, blk - return false unless @has_options_contract -- if @has_proc_contract && (args_contracts-2.is_a?(Hash) || args_contracts-2.is_a?(Contracts::Builtin::KeywordArgs)) && !args-2.is_a?(Hash) -- args.insert(-2, {}) -- elsif (args_contracts-1.is_a?(Hash) || args_contracts-1.is_a?(Contracts::Builtin::KeywordArgs)) && !args-1.is_a?(Hash) -- args << {} -+ if @has_proc_contract && args_contracts-2.is_a?(Contracts::Builtin::KeywordArgs) -+ args.insert(-2, kargs) -+ elsif args_contracts-1.is_a?(Contracts::Builtin::KeywordArgs) -+ args << kargs - end - true - end -diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb -index 9252c79..224b357 100644 ---- a/lib/contracts/call_with.rb -+++ b/lib/contracts/call_with.rb -@@ -1,17 +1,17 @@ - module Contracts - module CallWith -- def call_with(this, *args, &blk) -- call_with_inner(false, this, *args, &blk) -+ def call_with(this, *args, **kargs, &blk) -+ call_with_inner(false, this, *args, **kargs, &blk) - end - -- def call_with_inner(returns, this, *args, &blk) -+ def call_with_inner(returns, this, *args, **kargs, &blk) - args << blk if blk - - # Explicitly append blk=nil if nil != Proc contract violation anticipated - nil_block_appended = maybe_append_block!(args, blk) - - # Explicitly append options={} if Hash contract is present -- maybe_append_options!(args, blk) -+ kargs_appended = maybe_append_options!(args, kargs, blk) - - # Loop forward validating the arguments up to the splat (if there is one) - (@args_contract_index || args.size).times do |i| -@@ -57,14 +57,16 @@ module Contracts - validator = @args_validatorsargs_contracts.size - 1 - j - - unless validator && validatorarg -- return unless Contract.failure_callback(:arg => arg, -- :contract => contract, -- :class => klass, -- :method => method, -- :contracts => self, -- :arg_pos => i-1, -- :total_args => args.size, -- :return_value => false) -+ return unless Contract.failure_callback({ -+ :arg => arg, -+ :contract => contract, -+ :class => klass, -+ :method => method, -+ :contracts => self, -+ :arg_pos => i - 1, -+ :total_args => args.size, -+ :return_value => false, -+ }) - end - - if contract.is_a?(Contracts::Func) -@@ -76,15 +78,16 @@ module Contracts - # If we put the block into args for validating, restore the args - # OR if we added a fake nil at the end because a block wasn't passed in. - args.slice!(-1) if blk || nil_block_appended -+ args.slice!(-1) if kargs_appended - result = if method.respond_to?(:call) - # proc, block, lambda, etc -- method.call(*args, &blk) -+ method.call(*args, **kargs, &blk) - else - # original method name reference - # Don't reassign blk, else Travis CI shows "stack level too deep". - target_blk = blk - target_blk = lambda { |*params| blk.call(*params) } if blk && blk.is_a?(Contract) -- method.send_to(this, *args, &target_blk) -+ method.send_to(this, *args, **kargs, &target_blk) - end - - unless @ret_validatorresult -diff --git a/lib/contracts/invariants.rb b/lib/contracts/invariants.rb -index 56d2d82..215cb89 100644 ---- a/lib/contracts/invariants.rb -+++ b/lib/contracts/invariants.rb -@@ -46,10 +46,12 @@ module Contracts - def check_on(target, method) - return if target.instance_eval(&@condition) - -- self.class.failure_callback(:expected => expected, -- :actual => false, -- :target => target, -- :method => method) -+ self.class.failure_callback({ -+ :expected => expected, -+ :actual => false, -+ :target => target, -+ :method => method, -+ }) - end - - def self.failure_callback(data) -diff --git a/lib/contracts/method_handler.rb b/lib/contracts/method_handler.rb -index fe301cd..714e4e1 100644 ---- a/lib/contracts/method_handler.rb -+++ b/lib/contracts/method_handler.rb -@@ -107,7 +107,7 @@ module Contracts - current_engine = engine - - # We are gonna redefine original method here -- method_reference.make_definition(target) do |*args, &blk| -+ method_reference.make_definition(target) do |*args, **kargs, &blk| - engine = current_engine.nearest_decorated_ancestor - - # If we weren't able to find any ancestor that has decorated methods -@@ -130,14 +130,14 @@ module Contracts - last_error = nil - - decorated_methods.each do |decorated_method| -- result = decorated_method.call_with_inner(true, self, *args, &blk) -+ result = decorated_method.call_with_inner(true, self, *args, **kargs, &blk) - return result unless result.is_a?(ParamContractError) - last_error = result - end - - begin - if ::Contract.failure_callback(last_error.data, false) -- decorated_methods.last.call_with_inner(false, self, *args, &blk) -+ decorated_methods.last.call_with_inner(false, self, *args, **kargs, &blk) - end - rescue expected_error => final_error - raise final_error.to_contract_error -diff --git a/lib/contracts/method_reference.rb b/lib/contracts/method_reference.rb -index 0bc68f8..0c0c03f 100644 ---- a/lib/contracts/method_reference.rb -+++ b/lib/contracts/method_reference.rb -@@ -39,8 +39,8 @@ module Contracts - - # Calls original method on specified `this` argument with - # specified arguments `args` and block `&blk`. -- def send_to(this, *args, &blk) -- this.send(aliased_name, *args, &blk) -+ def send_to(this, *args, **kargs, &blk) -+ this.send(aliased_name, *args, **kargs, &blk) - end - - private -diff --git a/spec/builtin_contracts_spec.rb b/spec/builtin_contracts_spec.rb -index 00cf495..a9f7257 100644 ---- a/spec/builtin_contracts_spec.rb -+++ b/spec/builtin_contracts_spec.rb -@@ -376,10 +376,6 @@ RSpec.describe "Contracts:" do - fails { @o.hash_keywordargs(:hash => nil) } - fails { @o.hash_keywordargs(:hash => 1) } - end -- -- it "should pass if a method is overloaded with non-KeywordArgs" do -- passes { @o.person_keywordargs("name", 10) } -- end - end - - describe "Optional:" do -@@ -405,15 +401,15 @@ RSpec.describe "Contracts:" do - end - - context "given a fulfilled contract" do -- it { expect(@o.gives_max_value(:panda => 1, :bamboo => 2)).to eq(2) } -- it { expect(@o.pretty_gives_max_value(:panda => 1, :bamboo => 2)).to eq(2) } -+ it { expect(@o.gives_max_value({ :panda => 1, :bamboo => 2 })).to eq(2) } -+ it { expect(@o.pretty_gives_max_value({ :panda => 1, :bamboo => 2 })).to eq(2) } - end - - context "given an unfulfilled contract" do -- it { fails { @o.gives_max_value(:panda => "1", :bamboo => "2") } } -+ it { fails { @o.gives_max_value({ :panda => "1", :bamboo => "2" }) } } - it { fails { @o.gives_max_value(nil) } } - it { fails { @o.gives_max_value(1) } } -- it { fails { @o.pretty_gives_max_value(:panda => "1", :bamboo => "2") } } -+ it { fails { @o.pretty_gives_max_value({ :panda => "1", :bamboo => "2" }) } } - end - - describe "#to_s" do -@@ -430,25 +426,25 @@ RSpec.describe "Contracts:" do - describe "StrictHash:" do - context "when given an exact correct input" do - it "does not raise an error" do -- passes { @o.strict_person(:name => "calvin", :age => 10) } -+ passes { @o.strict_person({ :name => "calvin", :age => 10 }) } - end - end - - context "when given an input with correct keys but wrong types" do - it "raises an error" do -- fails { @o.strict_person(:name => "calvin", :age => "10") } -+ fails { @o.strict_person({ :name => "calvin", :age => "10" }) } - end - end - - context "when given an input with missing keys" do - it "raises an error" do -- fails { @o.strict_person(:name => "calvin") } -+ fails { @o.strict_person({ :name => "calvin" }) } - end - end - - context "when given an input with extra keys" do - it "raises an error" do -- fails { @o.strict_person(:name => "calvin", :age => 10, :soft => true) } -+ fails { @o.strict_person({ :name => "calvin", :age => 10, :soft => true }) } - end - end - -diff --git a/spec/contracts_spec.rb b/spec/contracts_spec.rb -index 72c8603..5586415 100644 ---- a/spec/contracts_spec.rb -+++ b/spec/contracts_spec.rb -@@ -349,19 +349,19 @@ RSpec.describe "Contracts:" do - - describe "Hashes" do - it "should pass for exact correct input" do -- expect { @o.person(:name => "calvin", :age => 10) }.to_not raise_error -+ expect { @o.person({ :name => "calvin", :age => 10 }) }.to_not raise_error - end - - it "should pass even if some keys don't have contracts" do -- expect { @o.person(:name => "calvin", :age => 10, :foo => "bar") }.to_not raise_error -+ expect { @o.person({ :name => "calvin", :age => 10, :foo => "bar" }) }.to_not raise_error - end - - it "should fail if a key with a contract on it isn't provided" do -- expect { @o.person(:name => "calvin") }.to raise_error(ContractError) -+ expect { @o.person({ :name => "calvin" }) }.to raise_error(ContractError) - end - - it "should fail for incorrect input" do -- expect { @o.person(:name => 50, :age => 10) }.to raise_error(ContractError) -+ expect { @o.person({ :name => 50, :age => 10 }) }.to raise_error(ContractError) - end - end - -@@ -612,16 +612,19 @@ RSpec.describe "Contracts:" do - - it "should contain to_s representation within a Hash contract" do - expect do -- @o.hash_complex_contracts(:rigged => "bad") -+ @o.hash_complex_contracts({ :rigged => "bad" }) - end.to raise_error(ContractError, not_s(delim "TrueClass or FalseClass")) - end - - it "should contain to_s representation within a nested Hash contract" do - expect do -- @o.nested_hash_complex_contracts(:rigged => true, -- :contents => { -- :kind => 0, -- :total => 42 }) -+ @o.nested_hash_complex_contracts({ -+ :rigged => true, -+ :contents => { -+ :kind => 0, -+ :total => 42, -+ }, -+ }) - end.to raise_error(ContractError, not_s(delim "String or Symbol")) - end - -diff --git a/spec/fixtures/fixtures.rb b/spec/fixtures/fixtures.rb -index b6d2bea..c42722e 100644 ---- a/spec/fixtures/fixtures.rb -+++ b/spec/fixtures/fixtures.rb -@@ -120,16 +120,11 @@ class GenericExample - end - - Contract C::KeywordArgs:name => String, :age => Fixnum => nil -- def person_keywordargs(data) -- end -- -- # Testing overloaded method -- Contract String, Fixnum => nil -- def person_keywordargs(name, age) -+ def person_keywordargs(name: "name", age: 10) - end - - Contract C::KeywordArgs:hash => C::HashOfSymbol, C::Num => nil -- def hash_keywordargs(data) -+ def hash_keywordargs(hash:) - end - - Contract (/foo/) => nil -diff --git a/spec/override_validators_spec.rb b/spec/override_validators_spec.rb -index 293c84c..25af373 100644 ---- a/spec/override_validators_spec.rb -+++ b/spec/override_validators_spec.rb -@@ -30,15 +30,15 @@ RSpec.describe Contract do - obj = klass.new - - expect do -- obj.something(:a => 35, :b => "hello") -+ obj.something({ :a => 35, :b => "hello" }) - end.to raise_error(ContractError) - - expect do -- obj.something( -+ obj.something({ - :a => 35, - :b => "hello", - :it_is_a_hash => true -- ) -+ }) - end.not_to raise_error - end - -diff --git a/spec/ruby_version_specific/contracts_spec_2.0.rb b/spec/ruby_version_specific/contracts_spec_2.0.rb -index 78c5e69..c2b3d69 100644 ---- a/spec/ruby_version_specific/contracts_spec_2.0.rb -+++ b/spec/ruby_version_specific/contracts_spec_2.0.rb -@@ -1,10 +1,10 @@ - class GenericExample -- Contract C::ArgsString, { repeat: C::MaybeC::Num } => C::ArrayOfString -+ Contract C::ArgsString, C::KeywordArgs repeat: C::MaybeC::Num => C::ArrayOfString - def splat_then_optional_named(*vals, repeat: 2) - vals.map { |v| v * repeat } - end - -- Contract ({foo: C::Nat}) => nil -+ Contract C::KeywordArgs foo: C::Nat => nil - def nat_test_with_kwarg(foo: 10) - end - -diff --git a/spec/validators_spec.rb b/spec/validators_spec.rb -index 588580e..22dc2a9 100644 ---- a/spec/validators_spec.rb -+++ b/spec/validators_spec.rb -@@ -34,7 +34,7 @@ RSpec.describe "Contract validators" do - - describe "within a hash" do - it "should pass for a matching string" do -- expect { o.hash_containing_foo(:host => "foo.example.org") }.to_not raise_error -+ expect { o.hash_containing_foo({ :host => "foo.example.org" }) }.to_not raise_error - end - end - --- -2.29.2 -
View file
_service:tar_scm:rubygem-contracts-0.16.0-0006-Remove-deprecated-const-fixnum.patch
Deleted
@@ -1,193 +0,0 @@ -From cbbebf804919e5ce675588adf854f6d7cdcf327a Mon Sep 17 00:00:00 2001 -From: wang--ge <wang__ge@126.com> -Date: Wed, 2 Aug 2023 10:41:57 +0800 -Subject: PATCH remove deprecated const fixnum - ---- - TUTORIAL.md | 28 ++++++++++++++-------------- - spec/fixtures/fixtures.rb | 18 +++++++++--------- - 2 files changed, 23 insertions(+), 23 deletions(-) - -diff --git a/TUTORIAL.md b/TUTORIAL.md -index c74ce06..3dc68af 100644 ---- a/TUTORIAL.md -+++ b/TUTORIAL.md -@@ -80,8 +80,8 @@ contracts.ruby comes with a lot of built-in contracts, including the following: - - * Logical combinations - * `Maybe`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Maybe) – specifies that a value _may be_ nil, e.g. `MaybeString` (equivalent to `OrString,nil`) -- * `Or`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Or) – passes if any of the given contracts pass, e.g. `OrFixnum, Float` -- * `Xor`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Xor) – passes if exactly one of the given contracts pass, e.g. `XorFixnum, Float` -+ * `Or`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Or) – passes if any of the given contracts pass, e.g. `OrInteger, Float` -+ * `Xor`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Xor) – passes if exactly one of the given contracts pass, e.g. `XorInteger, Float` - * `And`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/And) – passes if all contracts pass, e.g. `AndNat, -> (n) { n.even? }` - * `Not`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Not) – passes if all contracts fail for the given argument, e.g. `Notnil` - -@@ -89,7 +89,7 @@ contracts.ruby comes with a lot of built-in contracts, including the following: - * `ArrayOf`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/ArrayOf) – checks that the argument is an array, and all elements pass the given contract, e.g. `ArrayOfNum` - * `SetOf`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/SetOf) – checks that the argument is a set, and all elements pass the given contract, e.g. `SetOfNum` - * `HashOf`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/HashOf) – checks that the argument is a hash, and all keys and values pass the given contract, e.g. `HashOfSymbol => String` or `HashOfSymbol,String` -- * `StrictHash`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/StrictHash) – checks that the argument is a hash, and every key passed is present in the given contract, e.g. `StrictHash{ :description => String, :number => Fixnum }` -+ * `StrictHash`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/StrictHash) – checks that the argument is a hash, and every key passed is present in the given contract, e.g. `StrictHash{ :description => String, :number => Integer }` - * `RangeOf`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/RangeOf) – checks that the argument is a range whose elements (#first and #last) pass the given contract, e.g. `RangeOfDate` - * `Enum`(http://www.rubydoc.info/gems/contracts/Contracts/Builtin/Enum) – checks that the argument is part of a given collection of objects, e.g. `Enum:a, :b, :c` - -@@ -152,7 +152,7 @@ end - - You always need to specify a contract for the return value. In this example, `hello` doesn't return anything, so the contract is `nil`. Now you know that you can use a constant like `nil` as the end of a contract. Valid values for a contract are: - --- the name of a class (like `String` or `Fixnum`) -+- the name of a class (like `String` or `Integer`) - - a constant (like `nil` or `1`) - - a `Proc` that takes a value and returns true or false to indicate whether the contract passed or not - - a class that responds to the `valid?` class method (more on this later) -@@ -161,32 +161,32 @@ You always need to specify a contract for the return value. In this example, `he - ### A Double Function - - ```ruby --Contract C::OrFixnum, Float => C::OrFixnum, Float -+Contract C::OrInteger, Float => C::OrInteger, Float - def double(x) - 2 * x - end - ``` - - Sometimes you want to be able to choose between a few contracts. `Or` takes a variable number of contracts and checks the argument against all of them. If it passes for any of the contracts, then the `Or` contract passes. --This introduces some new syntax. One of the valid values for a contract is an instance of a class that responds to the `valid?` method. This is what `OrFixnum, Float` is. The longer way to write it would have been: -+This introduces some new syntax. One of the valid values for a contract is an instance of a class that responds to the `valid?` method. This is what `OrInteger, Float` is. The longer way to write it would have been: - - ```ruby --Contract C::Or.new(Fixnum, Float) => C::Or.new(Fixnum, Float) -+Contract C::Or.new(Integer, Float) => C::Or.new(Integer, Float) - ``` - - All the built-in contracts have overridden the square brackets (``) to give the same functionality. So you could write - - ```ruby --Contract C::OrFixnum, Float => C::OrFixnum, Float -+Contract C::OrInteger, Float => C::OrInteger, Float - ``` - - or - - ```ruby --Contract C::Or.new(Fixnum, Float) => C::Or.new(Fixnum, Float) -+Contract C::Or.new(Integer, Float) => C::Or.new(Integer, Float) - ``` - --whichever you prefer. They both mean the same thing here: make a new instance of `Or` with `Fixnum` and `Float`. Use that instance to validate the argument. -+whichever you prefer. They both mean the same thing here: make a new instance of `Or` with `Integer` and `Float`. Use that instance to validate the argument. - - ### A Product Function - -@@ -455,7 +455,7 @@ Now you can use `Person` wherever you would have used `OrHash, nil`. Your code - - Contracts are very easy to define. To re-iterate, there are 5 kinds of contracts: - --- the name of a class (like `String` or `Fixnum`) -+- the name of a class (like `String` or `Integer`) - - a constant (like `nil` or `1`) - - a `Proc` that takes a value and returns true or false to indicate whether the contract passed or not - - a class that responds to the `valid?` class method (more on this later) -@@ -511,7 +511,7 @@ The `Or` contract takes a sequence of contracts, and passes if any of them pass. - This class inherits from `CallableClass`, which allows us to use `` when using the class: - - ```ruby --Contract C::OrFixnum, Float => C::Num -+Contract C::OrInteger, Float => C::Num - def double(x) - 2 * x - end -@@ -520,7 +520,7 @@ end - Without `CallableClass`, we would have to use `.new` instead: - - ```ruby --Contract C::Or.new(Fixnum, Float) => C::Num -+Contract C::Or.new(Integer, Float) => C::Num - def double(x) - # etc - ``` -@@ -723,7 +723,7 @@ class MyBirthday < Struct.new(:day, :month) - invariant(:day) { 1 <= day && day <= 31 } - invariant(:month) { 1 <= month && month <= 12 } - -- Contract C::None => Fixnum -+ Contract C::None => Integer - def silly_next_day! - self.day += 1 - end -diff --git a/spec/fixtures/fixtures.rb b/spec/fixtures/fixtures.rb -index 55638c2..bf2042a 100644 ---- a/spec/fixtures/fixtures.rb -+++ b/spec/fixtures/fixtures.rb -@@ -100,11 +100,11 @@ class GenericExample - end - end - -- Contract ({ :name => String, :age => Fixnum }) => nil -+ Contract ({ :name => String, :age => Integer }) => nil - def person(data) - end - -- Contract C::StrictHash{ :name => String, :age => Fixnum } => nil -+ Contract C::StrictHash{ :name => String, :age => Integer } => nil - def strict_person(data) - end - -@@ -119,7 +119,7 @@ class GenericExample - def nested_hash_complex_contracts(data) - end - -- Contract C::KeywordArgs:name => String, :age => Fixnum => nil -+ Contract C::KeywordArgs:name => String, :age => Integer => nil - def person_keywordargs(name: "name", age: 10) - end - -@@ -529,30 +529,30 @@ class MyBirthday - @month = month - end - -- Contract C::None => Fixnum -+ Contract C::None => Integer - def silly_next_day! - self.day += 1 - end - -- Contract C::None => Fixnum -+ Contract C::None => Integer - def silly_next_month! - self.month += 1 - end - -- Contract C::None => Fixnum -+ Contract C::None => Integer - def clever_next_day! - return clever_next_month! if day == 31 - self.day += 1 - end - -- Contract C::None => Fixnum -+ Contract C::None => Integer - def clever_next_month! - return next_year! if month == 12 - self.month += 1 - self.day = 1 - end - -- Contract C::None => Fixnum -+ Contract C::None => Integer - def next_year! - self.month = 1 - self.day = 1 -@@ -610,7 +610,7 @@ with_enabled_no_contracts do - body + "!" - end - -- Contract Fixnum, String => String -+ Contract Integer, String => String - def on_response(status, body) - "error #{status}: #{body}" - end --- -2.33.0 -
View file
_service
Changed
@@ -2,7 +2,7 @@ <service name="tar_scm"> <param name="url">git@gitee.com:src-openeuler/rubygem-contracts.git</param> <param name="scm">git</param> - <param name="revision">openEuler-23.09</param> + <param name="revision">master</param> <param name="exclude">*</param> <param name="extract">*</param> </service>
View file
_service:tar_scm:contracts-0.16.0.gem/data/.travis.yml
Deleted
@@ -1,26 +0,0 @@ -dist: trusty - -language: ruby -rvm: - - "1.9.3" - - "2.0.0" - - "2.1" - - "2.2" - - "ruby-2.3.0" - -before_install: - - gem install bundler - -script: - - bundle exec rspec - - script/cucumber - - ruby script/rubocop.rb - -bundler_args: --without development - -matrix: - include: - - rvm: "1.9.2" - dist: precise - - rvm: jruby-19mode # JRuby in 1.9 mode - dist: precise
View file
_service:tar_scm:contracts-0.16.0.gem/data/script/cucumber
Deleted
@@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -if ruby -e 'exit(1) unless RUBY_VERSION.to_f >= 2.0'; then - bundle exec cucumber -fi
View file
_service:tar_scm:contracts-0.16.0.gem/checksums.yaml.gz -> _service:tar_scm:contracts-0.17.gem/checksums.yaml.gz
Changed
@@ -1,7 +1,7 @@ --- -SHA1: - metadata.gz: d2050dfd5418498598d0f857e3fe285daa65908c - data.tar.gz: 9d5ae5ad04a508233be8ec25b2fb657f2a2b713e +SHA256: + metadata.gz: cbf4bff58a593998c5902920fff3c0a808ca5eb97ec9cad3646df370435421c7 + data.tar.gz: 02e5cffce164a25ae463b22e9f8b85c810d50c9c2875d09a3e83751afebac012 SHA512: - metadata.gz: 714992e52ce0d9bdc52c1a0d0ee0c89b0541559e924d2e63e902f73d253c09343f37e8bec1c082ba5bdae76cf146835f09e252f273a617fd5235108b3d2b9f49 - data.tar.gz: 50518932f7576ddb8a092fa42267321b4502b87a45f96255d2673197075dbdaf9008b3096ce0753cfe57a39a0055c14326dfddeae81ef4ce4243157e55dadd08 + metadata.gz: c6911f4383b0140c40bc08c838a3044897c3c9ac3c577fae4b3806879cbfed12f044f8ee1336305b1599c10af1bfb5aabe9ae2e8f1f9ffd94774d4de789e8402 + data.tar.gz: 25c8ecfe04e846ba55d87b33a43e0a38422440d0a963066ac67217edd8ebc396cbb2309b50704ea6f4dc4609bacbfb3fb3b501ef0a40210fe1877df5c6fbb7f8
View file
_service:tar_scm:contracts-0.17.gem/data/.github/workflows/code_style_checks.yaml
Added
@@ -0,0 +1,36 @@ +name: Code Style Checks + +on: + pull_request: + branches: + - master + paths-ignore: + - 'README.md' + push: + branches: + - master + paths-ignore: + - 'README.md' + +jobs: + rubocop: + name: Rubocop + if: "contains(github.event.commits0.message, 'ci skip') == false" + strategy: + fail-fast: false + matrix: + os: + - ubuntu + ruby: + - "3.0" + runs-on: ${{ matrix.os }}-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run Rubocop + run: bundle exec rubocop
View file
_service:tar_scm:contracts-0.17.gem/data/.github/workflows/tests.yaml
Added
@@ -0,0 +1,41 @@ +name: Tests + +on: + pull_request: + branches: + - master + paths-ignore: + - 'README.md' + push: + branches: + - master + paths-ignore: + - 'README.md' + +jobs: + unit_tests: + name: Unit Tests + if: "contains(github.event.commits0.message, 'ci skip') == false" + strategy: + fail-fast: false + matrix: + os: + - ubuntu + ruby: + - "3.0" + test_command: "bundle exec rspec && bundle exec cucumber" + include: + - os: ubuntu + ruby: "3.0" + test_command: "bundle exec rspec" + runs-on: ${{ matrix.os }}-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Test + run: ${{ matrix.test_command }}
View file
_service:tar_scm:contracts-0.16.0.gem/data/.gitignore -> _service:tar_scm:contracts-0.17.gem/data/.gitignore
Changed
@@ -1,5 +1,6 @@ *.swp *.swo .* +!.github Gemfile.lock tmp/aruba
View file
_service:tar_scm:contracts-0.16.0.gem/data/.rubocop.yml -> _service:tar_scm:contracts-0.17.gem/data/.rubocop.yml
Changed
@@ -1,6 +1,17 @@ +inherit_from: .rubocop_todo.yml + AllCops: + TargetRubyVersion: 3.0 + DisplayCopNames: true + NewCops: disable Exclude: + - "benchmarks/**/*" - "tmp/**/*" + - "vendor/**/*" + - "script/**/*.rb" + - "spec/fixtures/*.rb" + - "spec/ruby_version_specific/*.rb" + - "spec/*.rb" # forces method defs to have params in parens Style/MethodDefParentheses: @@ -32,7 +43,7 @@ Enabled: false # changes x ** 2 to x**2 -Style/SpaceAroundOperators: +Layout/SpaceAroundOperators: Enabled: false # doesn't allow vars starting with _ @@ -50,7 +61,7 @@ # enforces line length of 80 # TODO enable -Metrics/LineLength: +Layout/LineLength: Enabled: false # triggered by Contract ({ :name => String, :age => Fixnum }) => nil @@ -95,7 +106,7 @@ Style/TrivialAccessors: Enabled: false -Style/MultilineOperationIndentation: +Layout/MultilineOperationIndentation: EnforcedStyle: indented # Asks you to use %w{array of words} if possible. @@ -105,12 +116,12 @@ # conflicts with contracts # we define contracts like `Baz = 1` -Style/ConstantName: +Naming/ConstantName: Enabled: false # `Contract` violates this, otherwise a good cop (enforces snake_case method names) # TODO possible to get this enabled but ignore `Contract`? -Style/MethodName: +Naming/MethodName: Enabled: false # checks for !! @@ -123,9 +134,30 @@ Enabled: false # Checks that braces used for hash literals have or don't have surrounding space depending on configuration. -Style/SpaceInsideHashLiteralBraces: +Layout/SpaceInsideHashLiteralBraces: Enabled: false # TODO enable Style/SpecialGlobalVars: Enabled: false + +Style/IfUnlessModifier: + Enabled: false + +Naming/MemoizedInstanceVariableName: + Enabled: false + +Layout/FirstHashElementIndentation: + EnforcedStyle: consistent + +Layout/HashAlignment: + EnforcedColonStyle: table + +Style/TrailingCommaInHashLiteral: + EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInArguments: + EnforcedStyleForMultiline: consistent_comma
View file
_service:tar_scm:contracts-0.17.gem/data/.rubocop_todo.yml
Added
@@ -0,0 +1,138 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2017-09-24 19:22:52 +0200 using RuboCop version 0.41.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +require: + - rubocop-performance + +# Offense count: 2 +Lint/NonLocalExitFromIterator: + Exclude: + - 'lib/contracts/call_with.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Performance/RedundantBlockCall: + Exclude: + - 'spec/builtin_contracts_spec.rb' + - 'spec/fixtures/fixtures.rb' + - 'spec/methods_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'lib/contracts/builtin_contracts.rb' + - 'lib/contracts/errors.rb' + - 'lib/contracts/method_handler.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'benchmarks/wrap_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'spec/builtin_contracts_spec.rb' + +# Offense count: 1 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'lib/contracts.rb' + +# Offense count: 1 +Style/IfInsideElse: + Exclude: + - 'lib/contracts/validators.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineHashBraceLayout: + Exclude: + - 'spec/contracts_spec.rb' + - 'spec/fixtures/fixtures.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'lib/contracts/builtin_contracts.rb' + - 'lib/contracts/errors.rb' + - 'lib/contracts/method_handler.rb' + - 'lib/contracts/version.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Style/NestedParenthesizedCalls: + Exclude: + - 'spec/contracts_spec.rb' + - 'spec/support_spec.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Exclude: + - 'lib/contracts.rb' + - 'lib/contracts/formatters.rb' + - 'lib/contracts/invariants.rb' + +# Offense count: 9 +# Cop supports --auto-correct. +Style/RedundantParentheses: + Exclude: + - 'benchmarks/hash.rb' + - 'lib/contracts.rb' + - 'spec/fixtures/fixtures.rb' + - 'spec/override_validators_spec.rb' + - 'spec/ruby_version_specific/contracts_spec_1.9.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: only_raise, only_fail, semantic +Style/SignalException: + Exclude: + - 'benchmarks/bench.rb' + - 'benchmarks/hash.rb' + - 'lib/contracts.rb' + - 'lib/contracts/builtin_contracts.rb' + - 'lib/contracts/engine/eigenclass.rb' + - 'lib/contracts/invariants.rb' + - 'lib/contracts/method_handler.rb' + - 'spec/contracts_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'lib/contracts/decorators.rb' + - 'spec/methods_spec.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AllowNamedUnderscoreVariables. +Style/TrailingUnderscoreVariable: + Exclude: + - 'lib/contracts/builtin_contracts.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantInterpolation: + Exclude: + - 'lib/contracts/formatters.rb'
View file
_service:tar_scm:contracts-0.16.0.gem/data/CHANGELOG.markdown -> _service:tar_scm:contracts-0.17.gem/data/CHANGELOG.markdown
Changed
@@ -1,14 +1,31 @@ -## v0.16.0 + +## v0.16.1 - 2021-04-17 + +v0.16.1: https://github.com/egonSchiele/contracts.ruby/compare/v0.16.0...v0.16.1 + +- Enhancement: Pretty-print contracts in error messages - Corey Farwell(https://github.com/frewsxcv) #289(https://github.com/egonSchiele/contracts.ruby/pull/289) +- Bugfix: Fix `attr_accessor_with_contract` with multiple attribute names input - Kevin Yeh(https://github.com/kyeah) #259(https://github.com/egonSchiele/contracts.ruby/pull/259) +- Bugfix: Fix "stack level too deep" in CI builds - md-work(https://github.com/md-work) #283(https://github.com/egonSchiele/contracts.ruby/pull/283) + +## v0.16.0 - 2017-04-24 + +v0.16.0: https://github.com/egonSchiele/contracts.ruby/compare/v0.15.0...v0.16.0 - **Support for Ruby 1.8 has been discontinued** - Corey Farwell(https://github.com/frewsxcv) #256(https://github.com/egonSchiele/contracts.ruby/pull/256) - Enhancement: Add a `Contracts::Attrs` module containing attribute w/ contracts utilities - Corey Farwell(https://github.com/frewsxcv) #255(https://github.com/egonSchiele/contracts.ruby/pull/255) - Bugfix: Fix StrictHash contract for extra keys - Maciej Malecki(https://github.com/smt116) #254(https://github.com/egonSchiele/contracts.ruby/pull/254) -## v0.15.0 +## v0.15.0 - 2017-02-24 + +v0.15.0: https://github.com/egonSchiele/contracts.ruby/compare/v0.14.0...v0.15.0 + - Bugfix: Func contract's return value isn't enforced with blocks - Piotr Szmielew(https://github.com/esse) #251(https://github.com/egonSchiele/contracts.ruby/pull/251) - Bugfx: Fix contracts used in AR-models - Gert Goet(https://github.com/eval) #237(https://github.com/egonSchiele/contracts.ruby/pull/237) -## v0.14.0 +## v0.14.0 - 2016-04-26 + +v0.14.0: https://github.com/egonSchiele/contracts.ruby/compare/v0.13.0...v0.14.0 + - Enhancement: Add StrictHash contract - Fyodor(https://github.com/cbrwizard) #236(https://github.com/egonSchiele/contracts.ruby/pull/236) - Bugfix: dont fail if something other than a hash is passed to a KeywordArgs - Dan Padilha(https://github.com/dpad) #234(https://github.com/egonSchiele/contracts.ruby/pull/234) - LICENSE ADDED: Simplified BSD (same as what is specified in the readme) - Charles Dale(https://github.com/chuckd) #233(https://github.com/egonSchiele/contracts.ruby/pull/233) @@ -16,20 +33,26 @@ - Bugfix for err case when KeywordArgs and Proc are used together - Aditya Bhargava(https://github.com/egonSchiele) #230(https://github.com/egonSchiele/contracts.ruby/pull/230) - Enhancement: Add DescendantOf contract - Miguel Palhas(https://github.com/naps62) #227(https://github.com/egonSchiele/contracts.ruby/pull/227) -## v0.13.0 +## v0.13.0 - 2016-01-25 + +v0.13.0: https://github.com/egonSchiele/contracts.ruby/compare/v0.12.0...v0.13.0 - Enhancement: Add support for Ruby 2.3 - Oleksii Fedorov(https://github.com/waterlink) #216(https://github.com/egonSchiele/contracts.ruby/pull/216) - Enhancement: Added Int, Nat and NatPos builtin contracts - Simon George(https://github.com/sfcgeorge) #212(https://github.com/egonSchiele/contracts.ruby/pull/212) - Bugfix: Allow contracts on singleton of subclass - Oleksii Federov(https://github.com/waterlink) #211(https://github.com/egonSchiele/contracts.ruby/pull/211) -## v0.12.0 +## v0.12.0 - 2015-09-15 + +v0.12.0: https://github.com/egonSchiele/contracts.ruby/compare/v0.11.0...v0.12.0 - Feature: add `Regexp` validator - Gert Goet(https://github.com/eval) #196(https://github.com/egonSchiele/contracts.ruby/pull/196) - Docs: bootstrap cucumber/aruba/relish setup - Oleksii Fedorov(https://github.com/waterlink) #195(https://github.com/egonSchiele/contracts.ruby/pull/195) - Bugfix: allow to `extend` module, that has `Contracts` or `Contracts::Core` included without harming current module/class `Contracts` functionality, see: #176(https://github.com/egonSchiele/contracts.ruby/issues/176) - Oleksii Fedorov(https://github.com/waterlink) #198(https://github.com/egonSchiele/contracts.ruby/pull/198) - Enhancement: add `include Contracts::Builtin` to allow users to use builtin contracts without `Contracts::` prefix together with `include Contracts::Core` - PikachuEXE(https://github.com/PikachuEXE) #199(https://github.com/egonSchiele/contracts.ruby/pull/199) -## v0.11.0 +## v0.11.0 - 2015-07-30 + +v0.11.0: https://github.com/egonSchiele/contracts.ruby/compare/v0.10.1...v0.11.0 - Enhancement: add `include Contracts::Core` that doesn't pollute the namespace as much as `include Contracts` - Oleksii Federov(https://github.com/waterlink) #185(https://github.com/egonSchiele/contracts.ruby/pull/185) - Bugfix: fail if a non-hash is provided to a `HashOf` contract - Abe Voelker(https://github.com/abevoelker) #190(https://github.com/egonSchiele/contracts.ruby/pull/190) @@ -38,11 +61,15 @@ - Feature: range contract added - Oleksii Fedorov(https://github.com/waterlink) #184(https://github.com/egonSchiele/contracts.ruby/pull/184) - Feature: enum contract added - Dennis Günnewig(https://github.com/dg-ratiodata) #181(https://github.com/egonSchiele/contracts.ruby/pull/181) -## v0.10.1 +## v0.10.1 - 2015-07-16 + +v0.10.1: https://github.com/egonSchiele/contracts.ruby/compare/v0.10...v0.10.1 - Enhancement: make `@pattern_match` instance variable not render ruby warning. Required to use new aruba versions in rspec tests - Dennis Günnewig(https://github.com/dg-ratiodata) #179(https://github.com/egonSchiele/contracts.ruby/pull/179) -## v0.10 +## v0.10 - 2015-07-07 + +v0.10: https://github.com/egonSchiele/contracts.ruby/compare/v0.9...v0.10 - Bugfix: make `MaybeProc` work correctly - Simon George(https://github.com/sfcgeorge) #142(https://github.com/egonSchiele/contracts.ruby/pull/142) - Bugfix: make `Func` contract verified when used as return contract - Rob Rosenbaum(https://github.com/robnormal) #145(https://github.com/egonSchiele/contracts.ruby/pull/145) @@ -53,7 +80,9 @@ - Feature: custom validators with `Contract.override_validator` - Oleksii Fedorov(https://github.com/waterlink) #159(https://github.com/egonSchiele/contracts.ruby/pull/159) - Feature: add builtin `RangeOf...` contract - Gavin Sinclair(https://github.com/gsinclair) #171(https://github.com/egonSchiele/contracts.ruby/pull/171) -## v0.9 +## v0.9 - 2015-04-24 + +v0.9: https://github.com/egonSchiele/contracts.ruby/compare/0.8...v0.9 - MAJOR fix in pattern-matching: If the return contract for a pattern-matched function fails, it should NOT try the next pattern-match function. Pattern-matching is only for params, not return values. - raise an error if multiple defns have the same contract for pattern matching. @@ -74,7 +103,7 @@ - Add `SetOf` contract - various small fixes -## v0.8 +## v0.8 - 2015-04-03 - code refactored (very slight loss of performance, big increase in readability) - fail when defining a contract on a module without `include Contracts::Modules`
View file
_service:tar_scm:contracts-0.16.0.gem/data/Gemfile -> _service:tar_scm:contracts-0.17.gem/data/Gemfile
Changed
@@ -1,17 +1,21 @@ -source "http://rubygems.org" +# frozen_string_literal: true + +source "https://rubygems.org" gemspec group :test do - gem "rspec" gem "aruba" gem "cucumber", "~> 1.3.20" - gem "rubocop", "~> 0.29.1" if RUBY_VERSION >= "2" + gem "rspec" + + gem "rubocop", ">= 1.0.0" + gem "rubocop-performance", ">= 1.0.0" end group :development do - gem "relish" gem "method_profiler" - gem "ruby-prof" gem "rake" + gem "relish" + gem "ruby-prof" end
View file
_service:tar_scm:contracts-0.16.0.gem/data/README.md -> _service:tar_scm:contracts-0.17.gem/data/README.md
Changed
@@ -1,4 +1,6 @@ -# contracts.ruby !Build Status(https://travis-ci.org/egonSchiele/contracts.ruby.png?branch=master)(https://travis-ci.org/egonSchiele/contracts.ruby) !Join the chat at https://gitter.im/egonSchiele/contracts.ruby(https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg)(https://gitter.im/egonSchiele/contracts.ruby) +This project is looking for a new maintainer! More details here(https://github.com/egonSchiele/contracts.ruby/issues/249) + +# contracts.ruby !GitHub Build Status(https://img.shields.io/github/workflow/status/egonSchiele/contracts.ruby/Tests?style=flat-square)(https://github.com/egonSchiele/contracts.ruby/actions?query=workflow%3ATests) !Join the chat at https://gitter.im/egonSchiele/contracts.ruby(https://img.shields.io/badge/gitter-join%20chat-brightgreen.svg)(https://gitter.im/egonSchiele/contracts.ruby) Contracts let you clearly – even beautifully – express how your code behaves, and free you from writing tons of boilerplate, defensive code. @@ -53,7 +55,7 @@ ## Tutorial -Check out this awesome tutorial(http://egonschiele.github.com/contracts.ruby). +Check out this awesome tutorial(https://egonschiele.github.io/contracts.ruby/). ## Use Cases @@ -81,7 +83,7 @@ **Q.** What Rubies can I use this with? -**A.** It's been tested with `1.9.2`, `1.9.3`, `2.0.0`, `2.1`, `2.2`, and `jruby` (1.9 mode). +**A.** It's been tested with `2.1`, `2.2`, `2.3`, `2.4`, `2.5`, `2.6` and `2.7`. If you're using the library, please let me know(https://github.com/egonSchiele) what project you're using it on :)
View file
_service:tar_scm:contracts-0.16.0.gem/data/Rakefile -> _service:tar_scm:contracts-0.17.gem/data/Rakefile
Changed
@@ -1,11 +1,6 @@ -if RUBY_VERSION >= "2" - task :default => :spec, :rubocop +# frozen_string_literal: true - require "rubocop/rake_task" - RuboCop::RakeTask.new -else - task :default => :spec -end +task :default => :spec task :add_tag do `git tag -a v#{Contracts::VERSION} -m 'v#{Contracts::VERSION}'`
View file
_service:tar_scm:contracts-0.16.0.gem/data/contracts.gemspec -> _service:tar_scm:contracts-0.17.gem/data/contracts.gemspec
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + require File.expand_path(File.join(__FILE__, "../lib/contracts/version")) Gem::Specification.new do |s| @@ -8,6 +10,11 @@ s.author = "Aditya Bhargava" s.email = "bluemangroupie@gmail.com" s.files = `git ls-files`.split("\n") - s.homepage = "http://github.com/egonSchiele/contracts.ruby" + s.homepage = "https://github.com/egonSchiele/contracts.ruby" s.license = "BSD-2-Clause" + s.required_ruby_version = ">= 3.0", "< 4" + s.post_install_message = " + 0.16.x will be the supporting Ruby 2.x and be feature frozen (only fixes will be released) + For Ruby 3.x use 0.17.x or later (might not be released yet) + " end
View file
_service:tar_scm:contracts-0.17.gem/data/dependabot.yml
Added
@@ -0,0 +1,20 @@ +version: 2 +updates: + - package-ecosystem: bundler + directory: "/" + schedule: + interval: monthly + time: "06:00" + timezone: Asia/Hong_Kong + open-pull-requests-limit: 10 + labels: + - "dependencies" + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: monthly + time: "06:00" + timezone: Asia/Hong_Kong + open-pull-requests-limit: 10 + labels: + - "dependencies"
View file
_service:tar_scm:contracts-0.17.gem/data/features/basics/pretty-print.feature
Added
@@ -0,0 +1,241 @@ +Feature: Pretty printing Contract violations + + Scenario: Big array argument being passed to big array method parameter + Given a file named "example.rb" with: + """ruby + require "contracts" + C = Contracts + + class Example + include Contracts::Core + + class << self + Contract + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol + => nil + def run(data) + nil + end + end + end + + puts Example.run( + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo" + ) + """ + When I run `ruby example.rb` + Then the output should contain: + """ + : Contract violation for argument 1 of 1: (ParamContractError) + Expected: (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + Actual: "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo" + Value guarded in: Example::run + With Contract: Array => NilClass + At: example.rb:17 + """ + + Scenario: Big array value being returned from method expecting different big array type + Given a file named "example.rb" with: + """ruby + require "contracts" + C = Contracts + + class Example + include Contracts::Core + + class << self + Contract C::None => + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol + + def run + + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo" + + end + end + end + + puts Example.run + """ + When I run `ruby example.rb` + Then the output should contain: + """ + : Contract violation for return value: (ReturnContractError) + Expected: (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + (String or Symbol), + Actual: "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo", + "foo", "foo" + Value guarded in: Example::run + With Contract: None => Array + At: example.rb:17 + """ + + Scenario: Big hash argument being passed to big hash method parameter + Given a file named "example.rb" with: + """ruby + require "contracts" + C = Contracts + + class Example + include Contracts::Core + + class << self + Contract ({ + a: C::OrString, Symbol, + b: C::OrString, Symbol, + c: C::OrString, Symbol, + d: C::OrString, Symbol, + e: C::OrString, Symbol, + f: C::OrString, Symbol, + g: C::OrString, Symbol + }) => nil + def run(data) + nil + end + end + end + + puts Example.run({ + a: "foo", "foo", + b: "foo", "foo", + c: "foo", "foo", + d: "foo", "foo", + e: "foo", "foo", + f: "foo", "foo", + g: "foo", "foo" + }) + """ + When I run `ruby example.rb` + Then the output should contain: + """ + : Contract violation for argument 1 of 1: (ParamContractError) + Expected: {:a=>(String or Symbol), + :b=>(String or Symbol), + :c=>(String or Symbol), + :d=>(String or Symbol), + :e=>(String or Symbol), + :f=>(String or Symbol), + :g=>(String or Symbol)}, + Actual: {:a=>"foo", "foo", + :b=>"foo", "foo", + :c=>"foo", "foo", + :d=>"foo", "foo", + :e=>"foo", "foo", + :f=>"foo", "foo", + :g=>"foo", "foo"} + Value guarded in: Example::run + With Contract: Hash => NilClass + At: example.rb:17 + """ + + Scenario: Big hash value being returned from method expecting different big hash type + Given a file named "example.rb" with: + """ruby + require "contracts" + C = Contracts + + class Example + include Contracts::Core + + class << self + Contract C::None => ({ + a: C::OrString, Symbol, + b: C::OrString, Symbol, + c: C::OrString, Symbol, + d: C::OrString, Symbol, + e: C::OrString, Symbol, + f: C::OrString, Symbol, + g: C::OrString, Symbol + }) + def run + { + a: "foo", "foo", + b: "foo", "foo", + c: "foo", "foo", + d: "foo", "foo", + e: "foo", "foo", + f: "foo", "foo", + g: "foo", "foo" + } + end + end + end + + puts Example.run + """ + When I run `ruby example.rb` + Then the output should contain: + """ + : Contract violation for return value: (ReturnContractError) + Expected: {:a=>(String or Symbol), + :b=>(String or Symbol), + :c=>(String or Symbol), + :d=>(String or Symbol), + :e=>(String or Symbol), + :f=>(String or Symbol), + :g=>(String or Symbol)}, + Actual: {:a=>"foo", "foo", + :b=>"foo", "foo", + :c=>"foo", "foo", + :d=>"foo", "foo", + :e=>"foo", "foo", + :f=>"foo", "foo", + :g=>"foo", "foo"} + Value guarded in: Example::run + With Contract: None => Hash + At: example.rb:17 + """
View file
_service:tar_scm:contracts-0.16.0.gem/data/features/support/env.rb -> _service:tar_scm:contracts-0.17.gem/data/features/support/env.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "aruba/cucumber" require "aruba/jruby" if RUBY_PLATFORM == "java"
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "contracts/attrs" require "contracts/builtin_contracts" require "contracts/decorators" @@ -51,7 +53,9 @@ end attr_reader :args_contracts, :ret_contract, :klass, :method + def initialize(klass, method, *contracts) + super(klass, method) unless contracts.last.is_a?(Hash) unless contracts.one? fail %{ @@ -93,17 +97,17 @@ last_contract = args_contracts.last penultimate_contract = args_contracts-2 @has_options_contract = if @has_proc_contract - penultimate_contract.is_a?(Hash) || penultimate_contract.is_a?(Contracts::Builtin::KeywordArgs) + penultimate_contract.is_a?(Contracts::Builtin::KeywordArgs) else - last_contract.is_a?(Hash) || last_contract.is_a?(Contracts::Builtin::KeywordArgs) + last_contract.is_a?(Contracts::Builtin::KeywordArgs) end # === @klass, @method = klass, method end - def pretty_contract c - c.is_a?(Class) ? c.name : c.class.name + def pretty_contract contract + contract.is_a?(Class) ? contract.name : contract.class.name end def to_s @@ -116,22 +120,60 @@ # This function is used by the default #failure_callback method # and uses the hash passed into the failure_callback method. def self.failure_msg(data) - expected = Contracts::Formatters::Expected.new(data:contract).contract - position = Contracts::Support.method_position(data:method) + indent_amount = 8 method_name = Contracts::Support.method_name(data:method) + # Header header = if data:return_value "Contract violation for return value:" else "Contract violation for argument #{data:arg_pos} of #{data:total_args}:" end - %{#{header} - Expected: #{expected}, - Actual: #{data:arg.inspect} - Value guarded in: #{data:class}::#{method_name} - With Contract: #{data:contracts} - At: #{position} } + # Expected + expected_prefix = "Expected: " + expected_value = Contracts::Support.indent_string( + Contracts::Formatters::Expected.new(data:contract).contract.pretty_inspect, + expected_prefix.length, + ).strip + expected_line = "#{expected_prefix}#{expected_value}," + + # Actual + actual_prefix = "Actual: " + actual_value = Contracts::Support.indent_string( + data:arg.pretty_inspect, + actual_prefix.length, + ).strip + actual_line = actual_prefix + actual_value + + # Value guarded in + value_prefix = "Value guarded in: " + value_value = "#{data:class}::#{method_name}" + value_line = value_prefix + value_value + + # Contract + contract_prefix = "With Contract: " + contract_value = data:contracts.to_s + contract_line = contract_prefix + contract_value + + # Position + position_prefix = "At: " + position_value = Contracts::Support.method_position(data:method) + position_line = position_prefix + position_value + + + header, + Contracts::Support.indent_string( + + expected_line, + actual_line, + value_line, + contract_line, + position_line, + .join("\n"), + indent_amount, + ), + .join("\n") end # Callback for when a contract fails. By default it raises @@ -147,7 +189,7 @@ # puts failure_msg(data) # exit # end - def self.failure_callback(data, use_pattern_matching = true) + def self.failure_callback(data, use_pattern_matching: true) if data:contracts.pattern_match? && use_pattern_matching return DEFAULT_FAILURE_CALLBACK.call(data) end @@ -207,19 +249,21 @@ # returns true if it appended nil def maybe_append_block! args, blk return false unless @has_proc_contract && !blk && - (@args_contract_index || args.size < args_contracts.size) + (@args_contract_index || args.size < args_contracts.size) + args << nil true end # Same thing for when we have named params but didn't pass any in. # returns true if it appended nil - def maybe_append_options! args, blk + def maybe_append_options! args, kargs, blk return false unless @has_options_contract - if @has_proc_contract && (args_contracts-2.is_a?(Hash) || args_contracts-2.is_a?(Contracts::Builtin::KeywordArgs)) && !args-2.is_a?(Hash) - args.insert(-2, {}) - elsif (args_contracts-1.is_a?(Hash) || args_contracts-1.is_a?(Contracts::Builtin::KeywordArgs)) && !args-1.is_a?(Hash) - args << {} + + if @has_proc_contract && args_contracts-2.is_a?(Contracts::Builtin::KeywordArgs) + args.insert(-2, kargs) + elsif args_contracts-1.is_a?(Contracts::Builtin::KeywordArgs) + args << kargs end true end
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/attrs.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/attrs.rb
Changed
@@ -1,13 +1,19 @@ +# frozen_string_literal: true + module Contracts module Attrs def attr_reader_with_contract(*names, contract) - Contract Contracts::None => contract - attr_reader(*names) + names.each do |name| + Contract Contracts::None => contract + attr_reader(name) + end end def attr_writer_with_contract(*names, contract) - Contract contract => contract - attr_writer(*names) + names.each do |name| + Contract contract => contract + attr_writer(name) + end end def attr_accessor_with_contract(*names, contract)
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/builtin_contracts.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/builtin_contracts.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "contracts/formatters" require "set" @@ -30,35 +32,35 @@ # Check that an argument is a positive number. class Pos def self.valid? val - val && val.is_a?(Numeric) && val > 0 + val.is_a?(Numeric) && val.positive? end end # Check that an argument is a negative number. class Neg def self.valid? val - val && val.is_a?(Numeric) && val < 0 + val.is_a?(Numeric) && val.negative? end end # Check that an argument is an +Integer+. class Int def self.valid? val - val && val.is_a?(Integer) + val.is_a?(Integer) end end # Check that an argument is a natural number (includes zero). class Nat def self.valid? val - val && val.is_a?(Integer) && val >= 0 + val.is_a?(Integer) && val >= 0 end end # Check that an argument is a positive natural number (excludes zero). class NatPos def self.valid? val - val && val.is_a?(Integer) && val > 0 + val.is_a?(Integer) && val.positive? end end @@ -96,6 +98,7 @@ # Example: <tt>OrFixnum, Float</tt> class Or < CallableClass def initialize(*vals) + super() @vals = vals end @@ -107,9 +110,11 @@ end def to_s + # rubocop:disable Style/StringConcatenation @vals0, @vals.size-1.map do |x| InspectWrapper.create(x) end.join(", ") + " or " + InspectWrapper.create(@vals-1).to_s + # rubocop:enable Style/StringConcatenation end end @@ -118,6 +123,7 @@ # Example: <tt>XorFixnum, Float</tt> class Xor < CallableClass def initialize(*vals) + super() @vals = vals end @@ -130,9 +136,11 @@ end def to_s + # rubocop:disable Style/StringConcatenation @vals0, @vals.size-1.map do |x| InspectWrapper.create(x) end.join(", ") + " xor " + InspectWrapper.create(@vals-1).to_s + # rubocop:enable Style/StringConcatenation end end @@ -141,6 +149,7 @@ # Example: <tt>AndFixnum, Float</tt> class And < CallableClass def initialize(*vals) + super() @vals = vals end @@ -152,9 +161,11 @@ end def to_s + # rubocop:disable Style/StringConcatenation @vals0, @vals.size-1.map do |x| InspectWrapper.create(x) end.join(", ") + " and " + InspectWrapper.create(@vals-1).to_s + # rubocop:enable Style/StringConcatenation end end @@ -164,6 +175,7 @@ # Example: <tt>RespondTo:password, :credit_card</tt> class RespondTo < CallableClass def initialize(*meths) + super() @meths = meths end @@ -185,6 +197,7 @@ # Example: <tt>Send:valid?</tt> class Send < CallableClass def initialize(*meths) + super() @meths = meths end @@ -204,11 +217,12 @@ # Example: <tt>ExactlyNumeric</tt> class Exactly < CallableClass def initialize(cls) + super() @cls = cls end def valid?(val) - val.class == @cls + val.instance_of?(@cls) end def to_s @@ -222,6 +236,7 @@ # Example: <tt>Enum:a, :b, :c</tt>? class Enum < CallableClass def initialize(*vals) + super() @vals = vals end @@ -235,6 +250,7 @@ # Example: <tt>EqClass</tt> class Eq < CallableClass def initialize(value) + super() @value = value end @@ -252,6 +268,7 @@ # Example: <tt>Notnil</tt> class Not < CallableClass def initialize(*vals) + super() @vals = vals end @@ -275,12 +292,14 @@ # Example: <tt>CollectionOfArray, Num</tt> class CollectionOf < CallableClass def initialize(collection_class, contract) + super() @collection_class = collection_class @contract = contract end def valid?(vals) return false unless vals.is_a?(@collection_class) + vals.all? do |val| res, _ = Contract.valid?(val, @contract) res @@ -298,7 +317,7 @@ end def new(contract) - @before_new && @before_new.call + @before_new&.call CollectionOf.new(@collection_class, contract) end @@ -324,7 +343,9 @@ # Example: <tt>ArgsOrString, Num</tt> class Args < CallableClass attr_reader :contract + def initialize(contract) + super() @contract = contract end @@ -343,6 +364,7 @@ # Example: <tt>RangeOfNat</tt>, <tt>RangeOfDate</tt>, ... class RangeOf < CallableClass def initialize(contract) + super() @contract = contract end @@ -364,6 +386,7 @@ INVALID_KEY_VALUE_PAIR = "You should provide only one key-value pair to HashOf contract" def initialize(key, value = nil) + super() if value @key = key @value = value @@ -376,6 +399,7 @@ def valid?(hash) return false unless hash.is_a?(Hash) + keys_match = hash.keys.map { |k| Contract.valid?(k, @key) }.all? vals_match = hash.values.map { |v| Contract.valid?(v, @value) }.all? @@ -400,6 +424,7 @@ attr_reader :contract_hash def initialize(contract_hash) + super() @contract_hash = contract_hash end @@ -417,12 +442,14 @@ # Example: <tt>KeywordArgs e: Range, f: OptionalNum </tt> class KeywordArgs < CallableClass def initialize(options) + super() @options = options end def valid?(hash) return false unless hash.is_a?(Hash) return false unless hash.keys - options.keys == + options.all? do |key, contract| Optional._valid?(hash, key, contract) end @@ -445,6 +472,7 @@ # Example: <tt>DescendantOf e: Range, f: OptionalNum </tt> class DescendantOf < CallableClass def initialize(parent_class) + super() @parent_class = parent_class end @@ -473,11 +501,13 @@ def self._valid?(hash, key, contract) return Contract.valid?(hashkey, contract) unless contract.is_a?(Optional) + contract.within_opt_hash! !hash.key?(key) || Contract.valid?(hashkey, contract) end def initialize(contract) + super() @contract = contract @within_opt_hash = false end @@ -506,6 +536,7 @@ def ensure_within_opt_hash return if within_opt_hash + fail ArgumentError, UNABLE_TO_USE_OUTSIDE_OF_OPT_HASH end @@ -531,7 +562,9 @@ # Example: <tt>FuncNum => Num # the function should take a number and return a number</tt> class Func < CallableClass attr_reader :contracts + def initialize(*contracts) + super() @contracts = contracts end end
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/call_with.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/call_with.rb
Changed
@@ -1,13 +1,19 @@ +# frozen_string_literal: true + module Contracts module CallWith - def call_with(this, *args, &blk) + def call_with(this, *args, **kargs, &blk) + call_with_inner(false, this, *args, **kargs, &blk) + end + + def call_with_inner(returns, this, *args, **kargs, &blk) args << blk if blk # Explicitly append blk=nil if nil != Proc contract violation anticipated nil_block_appended = maybe_append_block!(args, blk) # Explicitly append options={} if Hash contract is present - maybe_append_options!(args, blk) + kargs_appended = maybe_append_options!(args, kargs, blk) # Loop forward validating the arguments up to the splat (if there is one) (@args_contract_index || args.size).times do |i| @@ -16,14 +22,18 @@ validator = @args_validatorsi unless validator && validatorarg - return unless Contract.failure_callback(:arg => arg, - :contract => contract, - :class => klass, - :method => method, - :contracts => self, - :arg_pos => i+1, - :total_args => args.size, - :return_value => false) + data = { + arg: arg, + contract: contract, + class: klass, + method: method, + contracts: self, + arg_pos: i+1, + total_args: args.size, + return_value: false, + } + return ParamContractError.new("as return value", data) if returns + return unless Contract.failure_callback(data) end if contract.is_a?(Contracts::Func) && blk && !nil_block_appended @@ -51,14 +61,18 @@ validator = @args_validatorsargs_contracts.size - 1 - j unless validator && validatorarg - return unless Contract.failure_callback(:arg => arg, - :contract => contract, - :class => klass, - :method => method, - :contracts => self, - :arg_pos => i-1, - :total_args => args.size, - :return_value => false) + # rubocop:disable Style/SoleNestedConditional + return unless Contract.failure_callback({ + :arg => arg, + :contract => contract, + :class => klass, + :method => method, + :contracts => self, + :arg_pos => i - 1, + :total_args => args.size, + :return_value => false, + }) + # rubocop:enable Style/SoleNestedConditional end if contract.is_a?(Contracts::Func) @@ -70,22 +84,27 @@ # If we put the block into args for validating, restore the args # OR if we added a fake nil at the end because a block wasn't passed in. args.slice!(-1) if blk || nil_block_appended + args.slice!(-1) if kargs_appended result = if method.respond_to?(:call) # proc, block, lambda, etc - method.call(*args, &blk) + method.call(*args, **kargs, &blk) else - # original method name referrence - added_block = blk ? lambda { |*params| blk.call(*params) } : nil - method.send_to(this, *args, &added_block) + # original method name reference + # Don't reassign blk, else Travis CI shows "stack level too deep". + target_blk = blk + target_blk = lambda { |*params| blk.call(*params) } if blk.is_a?(Contract) + method.send_to(this, *args, **kargs, &target_blk) end unless @ret_validatorresult - Contract.failure_callback(:arg => result, - :contract => ret_contract, - :class => klass, - :method => method, - :contracts => self, - :return_value => true) + Contract.failure_callback({ + arg: result, + contract: ret_contract, + class: klass, + method: method, + contracts: self, + return_value: true, + }) end this.verify_invariants!(method) if this.respond_to?(:verify_invariants!)
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/core.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/core.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module Core def self.included(base) @@ -25,7 +27,7 @@ # NOTE: Workaround for `defined?(super)` bug in ruby 1.9.2 # source: http://stackoverflow.com/a/11181685 # bug: https://bugs.ruby-lang.org/issues/6644 - base.class_eval <<-RUBY + base.class_eval <<-RUBY, __FILE__, __LINE__ + 1 # TODO: deprecate # Required when contracts are included in global scope def Contract(*args)
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/decorators.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/decorators.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module MethodDecorators def self.extended(klass) @@ -25,6 +27,7 @@ class << self; attr_accessor :decorators; end def self.inherited(klass) + super name = klass.name.gsub(/^./) { |m| m.downcase } return if name =~ /^^A-Za-z_/ || name =~ /^0-9A-Za-z_/ @@ -33,11 +36,11 @@ # make a new method that is the name of your decorator. # that method accepts random args and a block. # inside, `decorate` is called with those params. - MethodDecorators.module_eval <<-ruby_eval, __FILE__, __LINE__ + 1 + MethodDecorators.module_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{klass}(*args, &blk) ::Contracts::Engine.fetch_from(self).decorate(#{klass}, *args, &blk) end - ruby_eval + RUBY_EVAL end def initialize(klass, method)
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/engine.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/engine.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "contracts/engine/base" require "contracts/engine/target" require "contracts/engine/eigenclass"
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/engine/base.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/engine/base.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module Engine # Contracts engine @@ -90,7 +92,7 @@ def nearest_decorated_ancestor current = klass current_engine = self - ancestors = current.ancestors1..-1 + ancestors = current.ancestors1.. while current && current_engine && !current_engine.decorated_methods? current = ancestors.shift @@ -109,8 +111,7 @@ end # No-op because it is safe to add decorators to normal classes - def validate! - end + def validate!; end def pop_decorators decorators.tap { clear_decorators }
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/engine/eigenclass.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/engine/eigenclass.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module Engine # Special case of contracts engine for eigenclasses @@ -27,8 +29,7 @@ end # No-op for eigenclasses - def set_eigenclass_owner - end + def set_eigenclass_owner; end # Fetches just eigenclasses decorators def all_decorators
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/engine/target.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/engine/target.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module Engine # Represents class in question
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/errors.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/errors.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @private # Base class for Contract errors # @@ -65,6 +67,7 @@ alias_method :to_s, :message def initialize(message = DEFAULT_MESSAGE) + super @message = message end end
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/formatters.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/formatters.rb
Changed
@@ -1,3 +1,7 @@ +# frozen_string_literal: true + +require "pp" + module Contracts # A namespace for classes related to formatting. module Formatters @@ -5,18 +9,19 @@ class Expected # @param full Boolean if false only unique `to_s` values will be output, # non unique values become empty string. - def initialize(contract, full = true) + def initialize(contract, full: true) @contract, @full = contract, full end # Formats any type of Contract. def contract(contract = @contract) - if contract.is_a?(Hash) + case contract + when Hash hash_contract(contract) - elsif contract.is_a?(Array) + when Array array_contract(contract) else - InspectWrapper.create(contract, @full) + InspectWrapper.create(contract, full: @full) end end @@ -24,14 +29,14 @@ def hash_contract(hash) @full = true # Complex values output completely, overriding @full hash.inject({}) do |repr, (k, v)| - repr.merge(k => InspectWrapper.create(contract(v), @full)) - end.inspect + repr.merge(k => InspectWrapper.create(contract(v), full: @full)) + end end # Formats Array contracts. def array_contract(array) @full = true - array.map { |v| InspectWrapper.create(contract(v), @full) }.inspect + array.map { |v| InspectWrapper.create(contract(v), full: @full) } end end @@ -40,8 +45,8 @@ module InspectWrapper # InspectWrapper is a factory, will never be an instance # @return ClassInspectWrapper, ObjectInspectWrapper - def self.create(value, full = true) - if value.class == Class + def self.create(value, full: true) + if value.instance_of?(Class) ClassInspectWrapper else ObjectInspectWrapper @@ -64,6 +69,7 @@ return @value.inspect if empty_val? return @value.to_s if plain? return delim(@value.to_s) if useful_to_s? + useful_inspect end @@ -94,7 +100,7 @@ end def useful_to_s? - # Useless to_s value or no custom to_s behavious defined + # Useless to_s value or no custom to_s behaviour defined !empty_to_s? && custom_to_s? end @@ -123,7 +129,7 @@ include InspectWrapper def custom_to_s? - !@value.to_s.match(/#\<\w+:.+\>/) + !@value.to_s.match(/#<\w+:.+>/) end def useful_inspect
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/invariants.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/invariants.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module Invariants def self.included(base) @@ -46,10 +48,12 @@ def check_on(target, method) return if target.instance_eval(&@condition) - self.class.failure_callback(:expected => expected, - :actual => false, - :target => target, - :method => method) + self.class.failure_callback({ + expected: expected, + actual: false, + target: target, + method: method, + }) end def self.failure_callback(data)
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/method_handler.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/method_handler.rb
Changed
@@ -1,15 +1,17 @@ +# frozen_string_literal: true + module Contracts # Handles class and instance methods addition # Represents single such method class MethodHandler METHOD_REFERENCE_FACTORY = { :class_methods => SingletonMethodReference, - :instance_methods => MethodReference + :instance_methods => MethodReference, } RAW_METHOD_STRATEGY = { :class_methods => lambda { |target, name| target.method(name) }, - :instance_methods => lambda { |target, name| target.instance_method(name) } + :instance_methods => lambda { |target, name| target.instance_method(name) }, } # Creates new instance of MethodHandler @@ -78,11 +80,13 @@ def pattern_matching? return @_pattern_matching if defined?(@_pattern_matching) + @_pattern_matching = decorated_methods.any? { |x| x.method != method_reference } end def mark_pattern_matching_decorators return unless pattern_matching? + decorated_methods.each(&:pattern_match!) end @@ -107,13 +111,13 @@ current_engine = engine # We are gonna redefine original method here - method_reference.make_definition(target) do |*args, &blk| + method_reference.make_definition(target) do |*args, **kargs, &blk| engine = current_engine.nearest_decorated_ancestor # If we weren't able to find any ancestor that has decorated methods # FIXME : this looks like untested code (commenting it out doesn't make specs red) unless engine - fail "Couldn't find decorator for method " + self.class.name + ":#{name}.\nDoes this method look correct to you? If you are using contracts from rspec, rspec wraps classes in it's own class.\nLook at the specs for contracts.ruby as an example of how to write contracts in this case." + fail "Couldn't find decorator for method #{self.class.name}:#{name}.\nDoes this method look correct to you? If you are using contracts from rspec, rspec wraps classes in it's own class.\nLook at the specs for contracts.ruby as an example of how to write contracts in this case." end # Fetch decorated methods out of the contracts engine @@ -125,31 +129,26 @@ # function. Otherwise we return the result. # If we run out of functions, we raise the last error, but # convert it to_contract_error. - success = false - i = 0 - result = nil + expected_error = decorated_methods0.failure_exception + last_error = nil - until success - decorated_method = decorated_methodsi - i += 1 - begin - success = true - result = decorated_method.call_with(self, *args, &blk) - rescue expected_error => error - success = false - unless decorated_methodsi - begin - ::Contract.failure_callback(error.data, false) - rescue expected_error => final_error - raise final_error.to_contract_error - end - end - end + decorated_methods.each do |decorated_method| + result = decorated_method.call_with_inner(true, self, *args, **kargs, &blk) + return result unless result.is_a?(ParamContractError) + + last_error = result end - # Return the result of successfully called method - result + begin + if ::Contract.failure_callback(last_error&.data, use_pattern_matching: false) + decorated_methods.last.call_with_inner(false, self, *args, **kargs, &blk) + end + # rubocop:disable Naming/RescuedExceptionsVariableName + rescue expected_error => final_error + raise final_error.to_contract_error + # rubocop:enable Naming/RescuedExceptionsVariableName + end end end @@ -157,7 +156,7 @@ return if decorators.size == 1 fail %{ -Oops, it looks like method '#{name}' has multiple contracts: +Oops, it looks like method '#{method_name}' has multiple contracts: #{decorators.map { |x| x10.inspect }.join("\n")} Did you accidentally put more than one contract on a single function, like so? @@ -181,7 +180,8 @@ return if matched.empty? - fail ContractError.new(%{ + fail ContractError.new( + %{ It looks like you are trying to use pattern-matching, but multiple definitions for function '#{method_name}' have the same contract for input parameters: @@ -189,7 +189,9 @@ #{(matched + decorator).map(&:to_s).join("\n")} Each definition needs to have a different contract for the parameters. - }, {}) + }, + {}, + ) end end end
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/method_reference.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/method_reference.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts # MethodReference represents original method reference that was # decorated by contracts.ruby. Used for instance methods. @@ -39,8 +41,8 @@ # Calls original method on specified `this` argument with # specified arguments `args` and block `&blk`. - def send_to(this, *args, &blk) - this.send(aliased_name, *args, &blk) + def send_to(this, *args, **kargs, &blk) + this.send(aliased_name, *args, **kargs, &blk) end private
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/support.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/support.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module Support class << self @@ -8,7 +10,7 @@ if file.nil? || line.nil? "" else - file + ":" + line.to_s + "#{file}:#{line}" end end @@ -42,6 +44,13 @@ target <= eigenclass_of(Object) end + def indent_string(string, amount) + string.gsub( + /^(?!$)/, + (string/^ \t/ || " ") * amount, + ) + end + private # Module eigenclass can be detected by its ancestor chain
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/validators.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/validators.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts module Validators DEFAULT_VALIDATOR_STRATEGIES = { @@ -9,6 +11,7 @@ Array => lambda do |contract| lambda do |arg| return false unless arg.is_a?(Array) && arg.length == contract.length + arg.zip(contract).all? do |_arg, _contract| Contract.valid?(_arg, _contract) end @@ -19,6 +22,7 @@ Hash => lambda do |contract| lambda do |arg| return false unless arg.is_a?(Hash) + contract.keys.all? do |k| Contract.valid?(argk, contractk) end @@ -59,7 +63,7 @@ :default => lambda do |contract| lambda { |arg| contract == arg } - end + end, }.freeze # Allows to override validator with custom one. @@ -90,7 +94,7 @@ else if contract.respond_to? :valid? :valid - elsif klass == Class || klass == Module + elsif Class, Module.include?(klass) :class else :default
View file
_service:tar_scm:contracts-0.16.0.gem/data/lib/contracts/version.rb -> _service:tar_scm:contracts-0.17.gem/data/lib/contracts/version.rb
Changed
@@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Contracts - VERSION = "0.16.0" + VERSION = "0.17" end
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/attrs_spec.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/attrs_spec.rb
Changed
@@ -9,11 +9,15 @@ @name_r = name @name_w = name @name_rw = name + + @name_r_2 = name + @name_w_2 = name + @name_rw_2 = name end - attr_reader_with_contract :name_r, String - attr_writer_with_contract :name_w, String - attr_accessor_with_contract :name_rw, String + attr_reader_with_contract :name_r, :name_r_2, String + attr_writer_with_contract :name_w, :name_w_2, String + attr_accessor_with_contract :name_rw, :name_rw_2, String end context "attr_reader_with_contract" do @@ -27,6 +31,16 @@ .to(raise_error(ReturnContractError)) end + it "getting valid type for second val" do + expect(Person.new("bob").name_r_2) + .to(eq("bob")) + end + + it "getting invalid type for second val" do + expect { Person.new(1.3).name_r_2 } + .to(raise_error(ReturnContractError)) + end + it "setting" do expect { Person.new("bob").name_r = "alice" } .to(raise_error(NoMethodError)) @@ -48,6 +62,16 @@ expect { Person.new("bob").name_w = 1.2 } .to(raise_error(ParamContractError)) end + + it "setting valid type for second val" do + expect(Person.new("bob").name_w_2 = "alice") + .to(eq("alice")) + end + + it "setting invalid type for second val" do + expect { Person.new("bob").name_w_2 = 1.2 } + .to(raise_error(ParamContractError)) + end end context "attr_accessor_with_contract" do @@ -70,6 +94,26 @@ expect { Person.new("bob").name_rw = 1.2 } .to(raise_error(ParamContractError)) end + + it "getting valid type for second val" do + expect(Person.new("bob").name_rw_2) + .to(eq("bob")) + end + + it "getting invalid type for second val" do + expect { Person.new(1.2).name_rw_2 } + .to(raise_error(ReturnContractError)) + end + + it "setting valid type for second val" do + expect(Person.new("bob").name_rw_2 = "alice") + .to(eq("alice")) + end + + it "setting invalid type for second val" do + expect { Person.new("bob").name_rw_2 = 1.2 } + .to(raise_error(ParamContractError)) + end end end end
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/builtin_contracts_spec.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/builtin_contracts_spec.rb
Changed
@@ -376,10 +376,6 @@ fails { @o.hash_keywordargs(:hash => nil) } fails { @o.hash_keywordargs(:hash => 1) } end - - it "should pass if a method is overloaded with non-KeywordArgs" do - passes { @o.person_keywordargs("name", 10) } - end end describe "Optional:" do @@ -405,15 +401,15 @@ end context "given a fulfilled contract" do - it { expect(@o.gives_max_value(:panda => 1, :bamboo => 2)).to eq(2) } - it { expect(@o.pretty_gives_max_value(:panda => 1, :bamboo => 2)).to eq(2) } + it { expect(@o.gives_max_value({ :panda => 1, :bamboo => 2 })).to eq(2) } + it { expect(@o.pretty_gives_max_value({ :panda => 1, :bamboo => 2 })).to eq(2) } end context "given an unfulfilled contract" do - it { fails { @o.gives_max_value(:panda => "1", :bamboo => "2") } } + it { fails { @o.gives_max_value({ :panda => "1", :bamboo => "2" }) } } it { fails { @o.gives_max_value(nil) } } it { fails { @o.gives_max_value(1) } } - it { fails { @o.pretty_gives_max_value(:panda => "1", :bamboo => "2") } } + it { fails { @o.pretty_gives_max_value({ :panda => "1", :bamboo => "2" }) } } end describe "#to_s" do @@ -430,25 +426,25 @@ describe "StrictHash:" do context "when given an exact correct input" do it "does not raise an error" do - passes { @o.strict_person(:name => "calvin", :age => 10) } + passes { @o.strict_person({ :name => "calvin", :age => 10 }) } end end context "when given an input with correct keys but wrong types" do it "raises an error" do - fails { @o.strict_person(:name => "calvin", :age => "10") } + fails { @o.strict_person({ :name => "calvin", :age => "10" }) } end end context "when given an input with missing keys" do it "raises an error" do - fails { @o.strict_person(:name => "calvin") } + fails { @o.strict_person({ :name => "calvin" }) } end end context "when given an input with extra keys" do it "raises an error" do - fails { @o.strict_person(:name => "calvin", :age => 10, :soft => true) } + fails { @o.strict_person({ :name => "calvin", :age => 10, :soft => true }) } end end
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/contracts_spec.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/contracts_spec.rb
Changed
@@ -7,7 +7,7 @@ it "should fail for insufficient arguments" do expect do @o.hello - end.to raise_error + end.to raise_error ArgumentError end it "should fail for insufficient contracts" do @@ -32,7 +32,7 @@ 1 end end - end.to raise_error + end.to raise_error NameError end end @@ -349,19 +349,19 @@ describe "Hashes" do it "should pass for exact correct input" do - expect { @o.person(:name => "calvin", :age => 10) }.to_not raise_error + expect { @o.person({ :name => "calvin", :age => 10 }) }.to_not raise_error end it "should pass even if some keys don't have contracts" do - expect { @o.person(:name => "calvin", :age => 10, :foo => "bar") }.to_not raise_error + expect { @o.person({ :name => "calvin", :age => 10, :foo => "bar" }) }.to_not raise_error end it "should fail if a key with a contract on it isn't provided" do - expect { @o.person(:name => "calvin") }.to raise_error(ContractError) + expect { @o.person({ :name => "calvin" }) }.to raise_error(ContractError) end it "should fail for incorrect input" do - expect { @o.person(:name => 50, :age => 10) }.to raise_error(ContractError) + expect { @o.person({ :name => 50, :age => 10 }) }.to raise_error(ContractError) end end @@ -612,16 +612,19 @@ it "should contain to_s representation within a Hash contract" do expect do - @o.hash_complex_contracts(:rigged => "bad") + @o.hash_complex_contracts({ :rigged => "bad" }) end.to raise_error(ContractError, not_s(delim "TrueClass or FalseClass")) end it "should contain to_s representation within a nested Hash contract" do expect do - @o.nested_hash_complex_contracts(:rigged => true, - :contents => { - :kind => 0, - :total => 42 }) + @o.nested_hash_complex_contracts({ + :rigged => true, + :contents => { + :kind => 0, + :total => 42, + }, + }) end.to raise_error(ContractError, not_s(delim "String or Symbol")) end @@ -637,6 +640,28 @@ end.to raise_error(ContractError, not_s(delim "String or Symbol")) end + it "should wrap and pretty print for long param contracts" do + expect do + @o.long_array_param_contracts(true) + end.to( + raise_error( + ParamContractError, + /\\(String or Symbol\),\n \(String or Symbol\),/ + ) + ) + end + + it "should wrap and pretty print for long return contracts" do + expect do + @o.long_array_return_contracts + end.to( + raise_error( + ReturnContractError, + /\\(String or Symbol\),\n \(String or Symbol\),/ + ) + ) + end + it "should not contain Contracts:: module prefix" do expect do @o.double("bad") @@ -696,7 +721,7 @@ it "should apply the contract to an inherited method" do c = Child.new expect { c.double(2) }.to_not raise_error - expect { c.double("asd") }.to raise_error + expect { c.double("asd") }.to raise_error ParamContractError end end
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/fixtures/fixtures.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/fixtures/fixtures.rb
Changed
@@ -120,16 +120,11 @@ end Contract C::KeywordArgs:name => String, :age => Fixnum => nil - def person_keywordargs(data) - end - - # Testing overloaded method - Contract String, Fixnum => nil - def person_keywordargs(name, age) + def person_keywordargs(name: "name", age: 10) end Contract C::KeywordArgs:hash => C::HashOfSymbol, C::Num => nil - def hash_keywordargs(data) + def hash_keywordargs(hash:) end Contract (/foo/) => nil @@ -152,6 +147,30 @@ def nested_array_complex_contracts(data) end + Contract + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol + => nil + def long_array_param_contracts(data) + end + + Contract C::None => + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol, + C::OrString, Symbol + + def long_array_return_contracts + end + Contract Proc => C::Any def do_call(&block) block.call
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/methods_spec.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/methods_spec.rb
Changed
@@ -36,19 +36,19 @@ end it "should enforce return value inside block with no other parameter" do - expect { obj.foo(&:to_s) }.to raise_error + expect { obj.foo(&:to_s) }.to raise_error ReturnContractError end it "should enforce return value inside block with other parameter" do - expect { obj.foo2(2) { |x| x.to_s } }.to raise_error + expect { obj.foo2(2) { |x| x.to_s } }.to raise_error ReturnContractError end it "should enforce return value inside lambda with no other parameter" do - expect { obj.bar lambda { |x| x.to_s } }.to raise_error + expect { obj.bar lambda { |x| x.to_s } }.to raise_error ReturnContractError end it "should enforce return value inside lambda with other parameter" do - expect { obj.bar2(2, lambda { |x| x.to_s }) }.to raise_error + expect { obj.bar2(2, lambda { |x| x.to_s }) }.to raise_error ReturnContractError end end end
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/override_validators_spec.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/override_validators_spec.rb
Changed
@@ -30,15 +30,15 @@ obj = klass.new expect do - obj.something(:a => 35, :b => "hello") + obj.something({ :a => 35, :b => "hello" }) end.to raise_error(ContractError) expect do - obj.something( + obj.something({ :a => 35, :b => "hello", :it_is_a_hash => true - ) + }) end.not_to raise_error end
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/ruby_version_specific/contracts_spec_2.0.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/ruby_version_specific/contracts_spec_2.0.rb
Changed
@@ -1,10 +1,10 @@ class GenericExample - Contract C::ArgsString, { repeat: C::MaybeC::Num } => C::ArrayOfString + Contract C::ArgsString, C::KeywordArgs repeat: C::MaybeC::Num => C::ArrayOfString def splat_then_optional_named(*vals, repeat: 2) vals.map { |v| v * repeat } end - Contract ({foo: C::Nat}) => nil + Contract C::KeywordArgs foo: C::Nat => nil def nat_test_with_kwarg(foo: 10) end
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/ruby_version_specific/contracts_spec_2.1.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/ruby_version_specific/contracts_spec_2.1.rb
Changed
@@ -51,7 +51,7 @@ end.to raise_error(ContractError) end - it "should fail when passed nil to an optional argument which contract shouldnt accept nil" do + it "should fail when passed nil to an optional argument which contract shouldn't accept nil" do expect do @o.complicated("a", true, :b, :c, 2.0, e: (1..5), f: nil, g: :d) do |x| x
View file
_service:tar_scm:contracts-0.16.0.gem/data/spec/validators_spec.rb -> _service:tar_scm:contracts-0.17.gem/data/spec/validators_spec.rb
Changed
@@ -34,7 +34,7 @@ describe "within a hash" do it "should pass for a matching string" do - expect { o.hash_containing_foo(:host => "foo.example.org") }.to_not raise_error + expect { o.hash_containing_foo({ :host => "foo.example.org" }) }.to_not raise_error end end
View file
_service:tar_scm:contracts-0.16.0.gem/metadata.gz -> _service:tar_scm:contracts-0.17.gem/metadata.gz
Changed
@@ -1,14 +1,14 @@ --- !ruby/object:Gem::Specification name: contracts version: !ruby/object:Gem::Version - version: 0.16.0 + version: '0.17' platform: ruby authors: - Aditya Bhargava autorequire: bindir: bin cert_chain: -date: 2017-04-24 00:00:00.000000000 Z +date: 2021-05-07 00:00:00.000000000 Z dependencies: description: This library provides contracts for Ruby. Contracts let you clearly express how your code behaves, and free you from writing tons of boilerplate, defensive @@ -18,10 +18,12 @@ extensions: extra_rdoc_files: files: +- ".github/workflows/code_style_checks.yaml" +- ".github/workflows/tests.yaml" - ".gitignore" - ".rspec" - ".rubocop.yml" -- ".travis.yml" +- ".rubocop_todo.yml" - CHANGELOG.markdown - Gemfile - LICENSE @@ -36,8 +38,10 @@ - benchmarks/wrap_test.rb - contracts.gemspec - cucumber.yml +- dependabot.yml - features/README.md - features/basics/functype.feature +- features/basics/pretty-print.feature - features/basics/simple_example.feature - features/builtin_contracts/README.md - features/builtin_contracts/and.feature @@ -85,7 +89,6 @@ - lib/contracts/support.rb - lib/contracts/validators.rb - lib/contracts/version.rb -- script/cucumber - script/docs-release - script/docs-staging - script/rubocop.rb @@ -104,11 +107,13 @@ - spec/support.rb - spec/support_spec.rb - spec/validators_spec.rb -homepage: http://github.com/egonSchiele/contracts.ruby +homepage: https://github.com/egonSchiele/contracts.ruby licenses: - BSD-2-Clause metadata: {} -post_install_message: +post_install_message: "\n 0.16.x will be the supporting Ruby 2.x and be feature + frozen (only fixes will be released)\n For Ruby 3.x use 0.17.x or later (might + not be released yet)\n " rdoc_options: require_paths: - lib @@ -116,15 +121,17 @@ requirements: - - ">=" - !ruby/object:Gem::Version - version: '0' + version: '3.0' + - - "<" + - !ruby/object:Gem::Version + version: '4' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: -rubyforge_project: -rubygems_version: 2.5.1 +rubygems_version: 3.0.3 signing_key: specification_version: 4 summary: Contracts for Ruby.
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2