From 8d8414b72270126ae46e332e4b965aa8c61c2711 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Fri, 28 Oct 2022 09:49:40 +0300 Subject: [PATCH] Skip on older Rubies --- spec/rspec/matchers/dsl_spec.rb | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/spec/rspec/matchers/dsl_spec.rb b/spec/rspec/matchers/dsl_spec.rb index db39d940f..57a99c3eb 100644 --- a/spec/rspec/matchers/dsl_spec.rb +++ b/spec/rspec/matchers/dsl_spec.rb @@ -354,9 +354,17 @@ def new_matcher(name, *expected, &block) (to_match <= five) || greater_than_ceiling(to_match) && not_divisible_by_divisor?(to_match) end - chain :and_smaller_than do |ceiling, inclusive: false| - @ceiling = ceiling - @ceiling_inclusive = inclusive + if RSpec::Support::RubyFeatures.kw_args_supported? + binding.eval(<<-CODE, __FILE__, __LINE__) + chain :and_smaller_than do |ceiling, inclusive: false| + @ceiling = ceiling + @ceiling_inclusive = inclusive + end + CODE + else + chain :and_smaller_than do |ceiling| + @ceiling = ceiling + end end chain :and_divisible_by do |divisor| @@ -365,10 +373,16 @@ def new_matcher(name, *expected, &block) private - def smaller_than_ceiling?(to_match) - if @ceiling_inclusive - to_match <= @ceiling - else + if RSpec::Support::RubyFeatures.kw_args_supported? + def smaller_than_ceiling?(to_match) + if @ceiling_inclusive + to_match <= @ceiling + else + to_match < @ceiling + end + end + else + def smaller_than_ceiling?(to_match) to_match < @ceiling end end @@ -427,7 +441,7 @@ def not_divisible_by_divisor?(to_match) fail_with 'expected 21 not to be bigger than 5 and smaller than 29 and divisible by 3' end - it "allows passing keyword args to chain block" do + it "allows passing keyword args to chain block", skip: !RSpec::Support::RubyFeatures.kw_args_supported? do match = matcher.and_smaller_than(10, inclusive: true).and_divisible_by(1) expect(10).to match end