[rspec-devel] spec_helper required multiple times
Brandon Keepers
bkeepers at gmail.com
Tue Nov 6 10:43:12 EST 2007
On Nov 6, 2007, at 10:26 AM, David Chelimsky wrote:
> On Nov 6, 2007 9:15 AM, Brandon Keepers <bkeepers at gmail.com> wrote:
>> spec_helper gets run multiple times during a spec run. Throw this at
>> the bottom of spec_helper:
>>
>> @x ||= 0
>> puts "requiring spec_helper: #{@x += 1}"
>>
>> Is this expected behavior? This seems to be caused by #require not
>> expanding paths, so it requires spec_helper once per unique require
>> statement (once per spec directory).
>>
>> It is resolved by wrapping the require at the top of each spec file
>> with expand_path:
>>
>> require File.expand_path(File.dirname(__FILE__) + '/../../
>> spec_helper')
>>
>> It seems to me like this is something that require should do
>> automatically. Thoughts?
>
> Do you mean that Ruby's require should do the right thing, that rspec
> should patch require to do the right thing, or that users should do
> the right thing?
Ideally I think Ruby's require should do the right thing, but that not
being the case, I don't think rspec should change that behavior. I
guess rspec's generators should call expand_path, encouraging users to
do the right thing.
I'll try to take this question farther upstream, but this issue
primarily effects rspec and testunit in practice since they require
the same file using different absolute paths, whereas other
applications rely on the load path and relative paths. Mainly I just
wanted to bring it up to see if anyone had any insights as to why
require works that way.
Brandon
More information about the rspec-devel
mailing list