From 7f3f2f2647a580d4a9f1a7834366a008d9778b88 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 12 May 2020 11:41:44 +0100 Subject: [PATCH 1/2] Pin to rspec-support --- Gemfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index e9fa3d7c8..1367472ce 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" gemspec branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp -%w[rspec rspec-core rspec-mocks rspec-support].each do |lib| +%w[rspec rspec-core rspec-mocks].each do |lib| library_path = File.expand_path("../../#{lib}", __FILE__) if File.exist?(library_path) && !ENV['USE_GIT_REPOS'] gem lib, :path => library_path @@ -12,6 +12,8 @@ branch = File.read(File.expand_path("../maintenance-branch", __FILE__)).chomp end end +gem "rspec-support", :git => "https://github.com/rspec/rspec-support.git", :branch => "add-send-to-with-keyword-args" + if RUBY_VERSION < '1.9.3' gem 'rake', '< 11.0.0' # rake 11 requires Ruby 1.9.3 or later elsif RUBY_VERSION < '2.0.0' From fa5788d83738ca55f5d6e174af0b6bbcc2b7e7e0 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 12 May 2020 11:43:46 +0100 Subject: [PATCH 2/2] Ensure that has_ matcher works silently with keyword arguments --- lib/rspec/matchers/built_in/has.rb | 2 +- spec/rspec/matchers/built_in/has_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/rspec/matchers/built_in/has.rb b/lib/rspec/matchers/built_in/has.rb index 94a3dc040..ae6e9a84a 100644 --- a/lib/rspec/matchers/built_in/has.rb +++ b/lib/rspec/matchers/built_in/has.rb @@ -65,7 +65,7 @@ def predicate_exists? end def predicate_matches? - @actual.__send__(predicate, *@args, &@block) + RSpec::Support::WithKeywordsWhenNeeded.send_to(@actual, predicate, *@args, &@block) end def predicate diff --git a/spec/rspec/matchers/built_in/has_spec.rb b/spec/rspec/matchers/built_in/has_spec.rb index fb740f7dd..55505e8bb 100644 --- a/spec/rspec/matchers/built_in/has_spec.rb +++ b/spec/rspec/matchers/built_in/has_spec.rb @@ -8,6 +8,24 @@ expect({ :a => "A" }).to have_key(:a) end + if RSpec::Support::RubyFeatures.required_kw_args_supported? + binding.eval(<<-CODE, __FILE__, __LINE__) + it 'supports the use of required keyword arguments' do + thing = Class.new { def has_keyword?(keyword:); keyword == 'a'; end } + expect(thing.new).to have_keyword(keyword: 'a') + end + CODE + end + + if RSpec::Support::RubyFeatures.kw_args_supported? + binding.eval(<<-CODE, __FILE__, __LINE__) + it 'supports the use of optional keyword arguments' do + thing = Class.new { def has_keyword?(keyword: 'b'); keyword == 'a'; end } + expect(thing.new).to have_keyword(keyword: 'a') + end + CODE + end + it "fails if #has_sym?(*args) returns false" do expect { expect({ :b => "B" }).to have_key(:a)