-
-
Notifications
You must be signed in to change notification settings - Fork 764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared contexts/examples files_organization / code_loading #3050
Comments
👋 Ruby itself has no auto requiring etc of any files by default, it places The pattern you mention is actually generated as part of a |
@JonRowe thanks for the quick reply. It is clear that Ruby does not load every file in project directories by itself. This responsibility was taken by My concern about file loading comes from this sentence: "I believe that every core feature should work out of the box". For example one of the There is a convention for rspec - load files with _spec.rb suffix. But "shared logic" is not a "spec" so it has to be loaded another way. I get it. However at the same time, I would love to have it explicitly mentioned in the documentation (so I will see that I can't fully rely on rspec autoload), not to mention to have it preloaded automatically without order conflicts (which may be resolved with already mentioned I'd love to update the documentation at least, if my reasons above make sense to you. |
A pr showing an example of how shared examples CAN be loaded is probably fine, but I would be opposed if it promotes the “one true way” of doing things. |
I won't argue that shared examples should work out of the box but they do work out of the box, you can (and people do) use them in spec files themselves (they're actually scoped by example group) and you can put them in your spec_helper, in fact thats whats you're doing by requiring extra files you're breaking up the spec helper. I agree it would be odd if a framework with an autoloading behaviour only loaded certain parts of it self and you had to autoload the rest, but thats not how I see RSpec here, the pattern for loading specs has a default In theory theres nothing stopping you configuring adding and zeitwerk to load your support folder but thats not a responsibility RSpec wishes to take on. |
@pirj @JonRowe thanks for the comments. I have carefully read them. I have also read more about rspec in docs, in the help command output, and in source code files. Now I see the ground you stand on and to be honest I agree with your points. I agree that it is not the rspec responsibility to do a sophisticated loading of ruby files. I will open a PR soon with a small README.md changes about how the shared contexts/examples may be loaded to be used in test cases. |
I was quite surprised that I could not use shared contexts feature out of the box in my ruby project.
Finally I found a solution.
Here is my directories structure:
Here is the necessary code in spec_helper.rb:
My point is: why do I need to require files placed in pretty much conventional directory for core feature?
Is there something I don't see?
My environment
The text was updated successfully, but these errors were encountered: