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' 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)