Skip to content

Add helpful warning message for shared example groups

Created by: devonestes

I found myself with a strange warning message not long ago saying the following:

WARNING: Shared example group 'a flagger_or_tagger' has been previously defined
at:
  /Users/devoncestes/esh/IRT/spec/services/shared_examples/flagger_or_tagger_spec.rb:10
...and you are now defining it at:
  /Users/devoncestes/esh/IRT/spec/services/shared_examples/flagger_or_tagger_spec.rb:10
The new definition will overwrite the original one.

Turns out that this was happening because the file in which we defined our shared example group ended in _spec.rb, which triggered the Rspec auto loading, thus creating the strange warning. I had no idea how this could happen until I opened up an issue (#2277 (closed)) and @myronmarston pointed out the error. I figured that a helpful warning message that could guide the user to fixing this warning themselves might be good to add, so I've done so here!

Merge request reports