Skip to content

Commit

Permalink
Skip on older Rubies
Browse files Browse the repository at this point in the history
  • Loading branch information
pirj committed Oct 28, 2022
1 parent 29b4f6e commit 8d8414b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions spec/rspec/matchers/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d8414b

Please sign in to comment.