[rspec-devel] [ rspec-Feature Requests-10814 ] Runner loads shared code, test cases require them again

noreply at rubyforge.org noreply at rubyforge.org
Wed Jun 6 00:22:21 EDT 2007


Feature Requests item #10814, was opened at 2007-05-13 23:03
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10814&group_id=797

Category: runner / command line
Group: None
Status: Open
Priority: 3
Submitted By: Assaf Arkin (assaf)
Assigned to: David Chelimsky (dchelimsky)
Summary: Runner loads shared code, test cases require them again

Initial Comment:
Our test directory contains one file that provides methods and behaviores shared by all other test files. To run individual files, each one requires that shared file. 

However, when running spec test, RSpec loads all the files from the test directory (and its sub-directories). So the file gets loaded once (by RSpec) and required once (by the test files), and interpreted twice (by Ruby). Some of the code doesn't like that.

The current workaround is to detect the second load and ignore it (e.g. unless defined?(SomeConst)). But given the amount of time it took to find the culprit and work around it, can RSpec require the file instead, or allow a directory of shared behaviors not loaded by default?

----------------------------------------------------------------------

>Comment By: Assaf Arkin (assaf)
Date: 2007-06-06 04:22

Message:
require is essentially load but it checks against
$LOADED_FEATURES, so you can always remove those entries
from $LOADED_FEATURES (or just keep a before copy and
replace it) in order to load the same test files again.

This wouldn't work for my test cases in DRb, but will work
for them on the command line.

In my opinion a long term solution can't assume that the
Ruby environment returns to pristine condition, and will
fork a new process each time the tests are run.


----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-06-05 22:16

Message:
Unfortunately, I'm going to have to revert this - this fix broke drb. We'll have to find a different solution.

----------------------------------------------------------------------

Comment By: Patrick Ritchie (pritchie)
Date: 2007-06-05 22:00

Message:
Reason: load is required for spec_server (drb) to work correctly. 

If we use require the behaviours only get checked on the first run of a given spec file. On subsequent runs we get the behaviours don't get loaded causing this problem:

http://rubyforge.org/pipermail/rspec-users/2007-May/001633.html



----------------------------------------------------------------------

Comment By: Assaf Arkin (assaf)
Date: 2007-05-16 05:00

Message:
Thanks!

Assaf

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-16 03:35

Message:
No reason. Fixed in r1958.

----------------------------------------------------------------------

Comment By: Assaf Arkin (assaf)
Date: 2007-05-16 02:21

Message:
More pain than it's worth. I'm going to have to explain to
every developer how to properly run the test cases, they're
of course not going to RTFM, so their first attempt will
fail miserably. And with each project deciding to exclude a
different file ...

Is there a particular reason for RSpec to use load instead
of require?

----------------------------------------------------------------------

Comment By: David Chelimsky (dchelimsky)
Date: 2007-05-16 00:35

Message:
How about an "exclude" command line option?

spec spec --exclude spec/shared.rb

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3152&aid=10814&group_id=797


More information about the rspec-devel mailing list