diff --git a/spec/rspec/core/shared_example_group_spec.rb b/spec/rspec/core/shared_example_group_spec.rb index 0a14b538e8..ca3c34691d 100644 --- a/spec/rspec/core/shared_example_group_spec.rb +++ b/spec/rspec/core/shared_example_group_spec.rb @@ -69,6 +69,59 @@ def find_implementation_block(registry, scope, name) expect(Kernel).to_not respond_to(shared_method_name) end + # These keyword specs cover all 4 of the keyword / keyword like syntax varients + # they should be warning free. + + if RSpec::Support::RubyFeatures.required_kw_args_supported? + it 'supports required keyword arguments' do + binding.eval(<<-CODE, __FILE__, __LINE__) + group.__send__ shared_method_name, "shared context expects keywords" do |foo:| + it "has an expected value" do + expect(foo).to eq("bar") + end + end + + group.__send__ shared_method_name, "shared context expects hash" do |a_hash| + it "has an expected value" do + expect(a_hash[:foo]).to eq("bar") + end + end + + group.it_behaves_like "shared context expects keywords", foo: "bar" + group.it_behaves_like "shared context expects keywords", { foo: "bar" } + + group.it_behaves_like "shared context expects hash", foo: "bar" + group.it_behaves_like "shared context expects hash", { foo: "bar" } + CODE + expect(group.run).to eq true + end + end + + if RSpec::Support::RubyFeatures.kw_args_supported? + it 'supports optional keyword arguments' do + binding.eval(<<-CODE, __FILE__, __LINE__) + group.__send__ shared_method_name, "shared context expects keywords" do |foo: nil| + it "has an expected value" do + expect(foo).to eq("bar") + end + end + + group.__send__ shared_method_name, "shared context expects hash" do |a_hash| + it "has an expected value" do + expect(a_hash[:foo]).to eq("bar") + end + end + + group.it_behaves_like "shared context expects keywords", foo: "bar" + group.it_behaves_like "shared context expects keywords", { foo: "bar" } + + group.it_behaves_like "shared context expects hash", foo: "bar" + group.it_behaves_like "shared context expects hash", { foo: "bar" } + CODE + expect(group.run).to eq true + end + end + it "displays a warning when adding an example group without a block", :unless => RUBY_VERSION == '1.8.7' do expect_warning_with_call_site(__FILE__, __LINE__ + 1) group.send(shared_method_name, 'name but no block') @@ -543,20 +596,6 @@ def self.bar; 'bar'; end expect(group).to have_example_descriptions("a different spec") end end - - if RSpec::Support::RubyFeatures.required_kw_args_supported? - binding.eval(<<-CODE, __FILE__, __LINE__) - context "supporting kwargs" do - __send__ shared_method_name, "shared context" do |foo:| - it "has an expected value" do - expect(foo).to eq("bar") - end - end - - it_behaves_like "shared context", foo: "bar" - end - CODE - end end end end