Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 2917dcb

Browse files
committed
Tweak keyword argument specs for shared examples
1 parent ddbb436 commit 2917dcb

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

spec/rspec/core/shared_example_group_spec.rb

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,38 @@ def find_implementation_block(registry, scope, name)
6969
expect(Kernel).to_not respond_to(shared_method_name)
7070
end
7171

72+
if RSpec::Support::RubyFeatures.required_kw_args_supported?
73+
it 'supports required keyword arguments' do
74+
binding.eval(<<-CODE, __FILE__, __LINE__)
75+
group.__send__ shared_method_name, "shared context" do |foo:|
76+
it "has an expected value" do
77+
expect(foo).to eq("bar")
78+
end
79+
end
80+
81+
group.it_behaves_like "shared context", foo: "bar"
82+
group.it_behaves_like "shared context", { foo: "bar" }
83+
CODE
84+
expect(group.run).to eq true
85+
end
86+
end
87+
88+
if RSpec::Support::RubyFeatures.kw_args_supported?
89+
it 'supports optional keyword arguments' do
90+
binding.eval(<<-CODE, __FILE__, __LINE__)
91+
group.__send__ shared_method_name, "shared context" do |foo: nil|
92+
it "has an expected value" do
93+
expect(foo).to eq("bar")
94+
end
95+
end
96+
97+
group.it_behaves_like "shared context", foo: "bar"
98+
group.it_behaves_like "shared context", { foo: "bar" }
99+
CODE
100+
expect(group.run).to eq true
101+
end
102+
end
103+
72104
it "displays a warning when adding an example group without a block", :unless => RUBY_VERSION == '1.8.7' do
73105
expect_warning_with_call_site(__FILE__, __LINE__ + 1)
74106
group.send(shared_method_name, 'name but no block')
@@ -543,20 +575,6 @@ def self.bar; 'bar'; end
543575
expect(group).to have_example_descriptions("a different spec")
544576
end
545577
end
546-
547-
if RSpec::Support::RubyFeatures.required_kw_args_supported?
548-
binding.eval(<<-CODE, __FILE__, __LINE__)
549-
context "supporting kwargs" do
550-
__send__ shared_method_name, "shared context" do |foo:|
551-
it "has an expected value" do
552-
expect(foo).to eq("bar")
553-
end
554-
end
555-
556-
it_behaves_like "shared context", foo: "bar"
557-
end
558-
CODE
559-
end
560578
end
561579
end
562580
end

0 commit comments

Comments
 (0)