Closed devonestes closed 8 years ago
The problem is that your shared group is defined in a file named *_spec.rb
, which matches the pattern of files RSpec looks to load automatically. Then you are also requiring it somewhere so it is loaded twice.
Just rename your file to something not ending in _spec.rb
so RSpec does not load it automatically.
Oh, great! Thanks for the tip, @myronmarston!
On second thought, do you think this warrants some sort of special message to the user with helpful information so they can fix cases like this? I'm not sure this happens all that frequently, but I just wanted to toss the idea out there.
That's not a bad idea. The logic could see that the file matches the configured pattern used to find spec files and mention that it should be renamed to not match the pattern if it's a support file intended to be loaded and used by other spec file. If it does not match the pattern then it should not mention that.
Want to take a stab at it?
Sure thing - I'll give it a whirl and see how far I get!
Thank you 🗡️ I just opened a PR on my Project to fix this really annoying warning issue!
for file in *.rb; do mv "$file" "${file/_spec.rb/.rb}"; done
All of our Shared Examples files were loading two times, because all of them ended with the _spec
suffix!! => https://github.com/rspec/rspec-core/issues/2277#issuecomment-230069423
That's why we had so many warning messages like this one!
Another option would be not to require files containing shared examples manually. Choose between those two options wisely, if your target is to avoid time-consuming constant autoloading, then manually requiring shared examples is something you should really consider doing.
Hey y'all,
So I just noticed today that I've bene getting a strange warning about a shared example group. See below:
I'm not really sure how it's being defined twice in the same place, but that's what this warning is telling me! This might not even be the cause of any real problems, but it seemed strange enough for me to bring up. If there's anything else I can provide to help, just let me know!