-
-
Notifications
You must be signed in to change notification settings - Fork 759
Interesting before(:each) order observation when using config.include #903
Comments
One other note - my work around is causing issues with the JavaScript test suite because it is executing before Capybara sets the current driver! I'll have to revert to relying upon tags (which isn't as reliable because there are multiple tags that could be used to adjust the Capybara driver). |
Hi, you've used the term Out on interest what happens when you run this:
|
I am indeed using ActiveSupport, but to simplify the demonstration code (and to eliminate a potential third-party effect) I modified it to use When I run the above code, I do indeed get the desired order:
So the issue, if it is one, is that Out of curiosity, I went through the I used the following code:
And got the following response:
|
And this is the order you get when there is no |
I believe so. I currently have the three test files in an isolated directory. I have a whole bunch of gems installed on the system, but no Gemfile in that directory. I am running If I run this using
I get:
I don't see any Rails stuff in there (I'm filtering out a bunch of common namespace modules to keep the list manageable, but you can refer those in the regex up above). |
rspec/rspec-rails#738 is not related to ActiveSupport::Concern, actually. It's more about how rspec-rails' example groups call I'm still trying to figure out the best way to solve the rspec-rails issue. My gut reaction is that there really is a problem that should be solved in rspec-core, but I don't have a specific solution yet. |
I believe this was fixed by #845, which was included in 2.14.0.rc1. To confirm, I ran your original example against rspec-core HEAD and this is the output I get:
...so it appears this is indeed fixed. Closing. If the fix doesn't work for you for some reason, comment here and we're happy to re-open. |
Sorry for the delay in responding, but I finally got around to testing my original issue against 2.14.0.rc1 and I can confirm that it does indeed resolve the issue. I reverted my DatabaseCleaner code, instrumented things well enough to confirm that I was indeed having issues due to the sequencing of the |
Glad to hear your issues been resolved :). |
The following code produces some interesting output. I'm not sure if this is the desired behavior or if it is a true bug, but it definitely caught me by surprise. I couldn't find anything in https://www.relishapp.com/rspec/rspec-core/docs/hooks/before-and-after-hooks! that addressed this specific issue, and I couldn't spot anything in the issues either. I did take note of #607 (comment), but I still feel the issue is at least worth discussing.
The output I get is:
I would have expected it to instead order it like so:
Notice that the
before(:each)
that gets included by the concern runs before the one defined usingconfig
. I would have expected allbefore(:each)
blocks defined by the config to run first, followed by those introduced by the concern and then the local. I did notice that the order of theafter(:each)
blocks corresponds to what I would have expected.I noticed this because I'm using an approach to database cleaning suggested by Avdi Grimm in http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/. When I extracted some code that uses
FactoryGirl.create
into a concern, I observed that the database started accumulating records from test to test! I solved the issue by usingconfig.before(:suite)
to do the initial wipe and then using a separate concern with thebefore(:each)
andafter(:each)
blocks to do the rest of the database cleaner work and making sure I callconfig.include
on that concern first.The text was updated successfully, but these errors were encountered: