Skip to content

Commit

Permalink
Wrap keyword args definitions in eval blocks for 1.8.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Apr 8, 2020
1 parent a9baeae commit 94c1d76
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/rspec/matchers/dsl_spec.rb
Expand Up @@ -30,6 +30,7 @@ def ok
end

if RSpec::Support::RubyFeatures.required_kw_args_supported?
binding.eval(<<-CODE, __FILE__, __LINE__)
it 'supports the use of required keyword arguments in definition block' do
RSpec::Matchers.define(:match_required_kw) do |bar:|
match { expect(actual).to eq bar }
Expand All @@ -45,9 +46,11 @@ def kw(a:)
RSpec::Matchers.define(:matcher_required_kw_on_method) {}
expect(matcher_required_kw_on_method.kw(a: 1)).to eq(1)
end
CODE
end

if RSpec::Support::RubyFeatures.kw_args_supported?
binding.eval(<<-CODE, __FILE__, __LINE__)
it 'supports the use of optional keyword arguments in definition block' do
RSpec::Matchers.define(:match_optional_kw) do |bar: nil|
match { expect(actual).to eq bar }
Expand All @@ -63,6 +66,7 @@ def optional_kw(a: nil)
RSpec::Matchers.define(:matcher_optional_kw_on_method) {}
expect(matcher_optional_kw_on_method.optional_kw(a: 1)).to eq(1)
end
CODE
end

it "clears user instance variables between invocations" do
Expand Down

0 comments on commit 94c1d76

Please sign in to comment.