[rspec-devel] spec_helper required multiple times

David Chelimsky dchelimsky at gmail.com
Tue Nov 6 10:49:16 EST 2007


On Nov 6, 2007 9:43 AM, Brandon Keepers <bkeepers at gmail.com> wrote:
>
> 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.

Totally agree - would you kindly put in a feature request for that? Or
a patch even?

> 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.

Ah - got it. That does seem to be a deficiency.

Cheers,
David

>
>
> Brandon
> _______________________________________________
> rspec-devel mailing list
> rspec-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-devel
>


More information about the rspec-devel mailing list