-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use require
to load support files instead of load
#1043
Comments
I don't believe there's a good reason for using I'm not near the code but do all the tests pass if you change it? |
Thanks for thinking about it. It looks like there are about 70 failures. |
Ah interesting. The test failures seem to mostly be down to this which allows all Cucumber's own tests to be run in the same Ruby process. This is for performance - it's much slower to run the test suite when we work with files and processes for each scenario. So Cucumber itself might work fine, but our tests are relying on the use of What do you think @roberts1000? Are you keen to dig any deeper? |
So you're saying there's a chance.... :) I wish I could contribute more to the discussion at this point, but this the first time I've looked at the internals of Cucumber. I'm interested in digging deeper. I'll need to carve out some time to get up to speed on Cucumber development. |
@roberts1000 have you tried using require_relative instead of require?
And it works just fine. Now, if what you need is to have a file loaded first, then you can simply use require_relative from env.rb itself, for instance, I have a base_page.rb file where I have defined my Page class, that all my other pages inherit from, but I didn't want to have to require it in all the page files, so in my env file I just did this:
And now it is loaded before all the other support files, so I can use its contents from anywhere. |
We can use
If Cucumber used |
@alvaroemmanuel it is not the order which is the issue, it is the fact that it will load a file more than once and thus execute any dangling code multiple times. |
Thinking about this some more, I wonder if we could have two, configurable strategies, so the user can choose whether to use |
Got it, and agree, I think it would be preferred 99% of time to use |
run into the similar problem, one workaround is to put the base class file or included rb file in folders to have them in right order with folder name, say
this way, classes in _base folder are loaded first, then other folders. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs. |
It's still pending and should not be closed. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs. |
Fun-fighting the bot. |
This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective. |
Argh, the bot, why are you so ignorant? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Added "Slow burner" label, to stop Stalebot from closing the issue. |
If @mattwynne or @roberts1000 could point me to some active links (Given the original links are 3 years old nearly), I'll have a little dive into this as most of the tidying up I did for rails is now in PR. Not saying I'll get anywhere with this, but I'll take a stab |
Hi @luke-hill. I haven't followed the project in a while so I'm out the loop. I did a quick search for |
@mattwynne Can I get you to look over a mini-spike I have for this, at some point in the next few days. I've found it quite easy to switch these through configuration settings (I've got 2 different ways of doing this, so have pushed both into a branch), I'm just writing a couple of unit tests as an initial POC. I'll push something up to this repo tonight/tomorrow. Obviously I have no idea if that's what you're happy with. I encountered the same issue as @roberts1000 - One unit test fails precisely because it prevents this functionality (Being able to only load once), and then a truckload of tests fail because aruba re-writes to the same temporary file names, which obviously won't be re-loaded in during the same ruby thread being used and as such about 50% of the features fail for |
So I think the only thing I'd like to suggest here is that we make |
We currently monkey-patch Cucumber to avoid this issue: module Monkey
module Cucumber
module Glue
module RequireLoader
def load_code_file(code_file)
return unless File.extname(code_file) == '.rb'
require File.expand_path(code_file)
end
end
end
end
end
Cucumber::Glue::RegistryAndMore.prepend(Monkey::Cucumber::Glue::RequireLoader) The reason is that we use require_all gem to autoload all the support code and having Cucumber also load them ends up with constants being redfined. |
Ironically I write about this in the blog post coming out @p0deje, so I will be able to cover this use case. I'll alter the usage accordingly @mattwynne in the PR and fix up the tests / merge with master |
This is now in |
@luke-hill Do you know if this will fix things for cucumber-rails as well? Or is it necessary to do a similar change over there? |
As cucumber-rails uses cucumber then yes it "should" fix things. Obviously with a variety of auto-loaders present things may get messy. Once we've released a cut of the gem which is compatible, we will update people accordingly. |
@luke-hill Looking forward to the release. Thanks for fixing this! |
@stripedpumpkin - I just realised that as we now have an rc cut of this gem, we could do a new version of cucumber-rails for this if you would like? |
@luke-hill That would be great. We could try it on a branch and see how that goes. |
I've run into a situation where I would like to control the load order for files in the
features/support
folder.I got the impression, from reading The Cucumber Book, that Cucumber would behave similar to RSpec and only autoload
features/support/
. I tried moving the files intofeatures/setup/
and manually requiring the files fromenv.rb
. I quickly discovered that Cucumber wants to take over and load everything, regardless of the sub folder. (To be precise, RSpec doesn't autoload files inspec/support
unless it's specifically configured to do so.)Next I tried moving all the files back into the
features/support
folder, but having File A explicitly require File B t to make sure File B is loaded before File A is executed. Unfortunately, this doesn't work either because Cucumber uses theload
method to load the support files. Is there any reason Cucumber couldn't userequire
instead ofload
in this method?https://github.com/cucumber/cucumber-ruby/blob/master/lib/cucumber/rb_support/rb_language.rb#L107
That would give us much more flexibility in controlling the order of how support files are loaded.
require
would guarantee the file is only loaded once. It wouldn't matter if Cucumber got to it first or I manually required it somewhere.As it stands now, my only options are to combine the two dependent files into a single file, OR, move files outside of the feature folders; neither of which are good options. The use of
load
blocks any attempt to establish order because it will blindly load the file even if it has already been loaded.The text was updated successfully, but these errors were encountered: