@@ -69,6 +69,59 @@ def find_implementation_block(registry, scope, name)
69
69
expect ( Kernel ) . to_not respond_to ( shared_method_name )
70
70
end
71
71
72
+ # These keyword specs cover all 4 of the keyword / keyword like syntax varients
73
+ # they should be warning free.
74
+
75
+ if RSpec ::Support ::RubyFeatures . required_kw_args_supported?
76
+ it 'supports required keyword arguments' do
77
+ binding . eval ( <<-CODE , __FILE__ , __LINE__ )
78
+ group.__send__ shared_method_name, "shared context expects keywords" do |foo:|
79
+ it "has an expected value" do
80
+ expect(foo).to eq("bar")
81
+ end
82
+ end
83
+
84
+ group.__send__ shared_method_name, "shared context expects hash" do |a_hash|
85
+ it "has an expected value" do
86
+ expect(a_hash[:foo]).to eq("bar")
87
+ end
88
+ end
89
+
90
+ group.it_behaves_like "shared context expects keywords", foo: "bar"
91
+ group.it_behaves_like "shared context expects keywords", { foo: "bar" }
92
+
93
+ group.it_behaves_like "shared context expects hash", foo: "bar"
94
+ group.it_behaves_like "shared context expects hash", { foo: "bar" }
95
+ CODE
96
+ expect ( group . run ) . to eq true
97
+ end
98
+ end
99
+
100
+ if RSpec ::Support ::RubyFeatures . kw_args_supported?
101
+ it 'supports optional keyword arguments' do
102
+ binding . eval ( <<-CODE , __FILE__ , __LINE__ )
103
+ group.__send__ shared_method_name, "shared context expects keywords" do |foo: nil|
104
+ it "has an expected value" do
105
+ expect(foo).to eq("bar")
106
+ end
107
+ end
108
+
109
+ group.__send__ shared_method_name, "shared context expects hash" do |a_hash|
110
+ it "has an expected value" do
111
+ expect(a_hash[:foo]).to eq("bar")
112
+ end
113
+ end
114
+
115
+ group.it_behaves_like "shared context expects keywords", foo: "bar"
116
+ group.it_behaves_like "shared context expects keywords", { foo: "bar" }
117
+
118
+ group.it_behaves_like "shared context expects hash", foo: "bar"
119
+ group.it_behaves_like "shared context expects hash", { foo: "bar" }
120
+ CODE
121
+ expect ( group . run ) . to eq true
122
+ end
123
+ end
124
+
72
125
it "displays a warning when adding an example group without a block" , :unless => RUBY_VERSION == '1.8.7' do
73
126
expect_warning_with_call_site ( __FILE__ , __LINE__ + 1 )
74
127
group . send ( shared_method_name , 'name but no block' )
0 commit comments