@@ -213,20 +213,35 @@ def valid_name?(candidate)
213
213
214
214
def warn_if_key_taken ( context , key , new_block )
215
215
existing_module = shared_example_groups [ context ] [ key ]
216
-
217
216
return unless existing_module
218
217
219
- RSpec . warn_with <<-WARNING . gsub ( /^ +\| / , '' ) , :call_site => nil
220
- |WARNING: Shared example group '#{ key } ' has been previously defined at:
221
- | #{ formatted_location existing_module . definition }
222
- |...and you are now defining it at:
223
- | #{ formatted_location new_block }
224
- |The new definition will overwrite the original one.
225
- WARNING
218
+ old_definition_location = formatted_location existing_module . definition
219
+ new_definition_location = formatted_location new_block
220
+ loaded_spec_files = RSpec . configuration . loaded_spec_files
221
+
222
+ if loaded_spec_files . include? ( new_definition_location ) && old_definition_location == new_definition_location
223
+ RSpec . warn_with <<-WARNING . gsub ( /^ +\| / , '' ) , :call_site => nil
224
+ |WARNING: Your shared example group, '#{ key } ', defined at:
225
+ | #{ old_definition_location }
226
+ |was automatically loaded by RSpec because the file name
227
+ |matches the configured autoloading pattern (#{ RSpec . configuration . pattern } ),
228
+ |and is also being required from somewhere else. To fix this
229
+ |warning, either rename the file to not match the pattern, or
230
+ |do not explicitly require the file.
231
+ WARNING
232
+ else
233
+ RSpec . warn_with <<-WARNING . gsub ( /^ +\| / , '' ) , :call_site => nil
234
+ |WARNING: Shared example group '#{ key } ' has been previously defined at:
235
+ | #{ old_definition_location }
236
+ |...and you are now defining it at:
237
+ | #{ new_definition_location }
238
+ |The new definition will overwrite the original one.
239
+ WARNING
240
+ end
226
241
end
227
242
228
243
def formatted_location ( block )
229
- block . source_location . join ":"
244
+ block . source_location . join ( ":" ) . gsub ( /:in.*$/ , '' )
230
245
end
231
246
232
247
if Proc . method_defined? ( :source_location )
0 commit comments