[rspec-users] Can I run the same specs with different gems? Ideas?

Rick DeNatale rick.denatale at gmail.com
Sun May 17 12:00:46 EDT 2009

On Sun, May 17, 2009 at 9:46 AM, Rick DeNatale <rick.denatale at gmail.com> wrote:

> So I tried to make a spectask to run the specs after require in
> activesupport by adding this in my rake file:
> desc "Run all specs with activesupport"
> Spec::Rake::SpecTask.new(:spec_as) do |t|
>  t.spec_opts = ['--options', "spec/spec.opts"]
>  t.ruby_opts = ['-rrubygems', '-ractive_support']
>  t.spec_files = FileList['spec/**/*_spec.rb']
>  t.verbose = true
> end
> Unfortunately, it seems that the ruby command only handles a single -r
> option, the -rrubygems gets ignored and things fail because it can't
> find active_support.rb, the same thing happens if I just try:
> $ruby -rrubygems -ractive_support -e'puts "Hello"'
> Right now the only approach I can think of is to somehow set an
> environment variable which my spec helper would look at to determine
> whether to require activesupport, but I don't even know if that's
> possible with Kernel#system particularly in a platform independent
> way.

Follow up.  I figured it out.  The problem wasn't that Ruby doesn't
allow multiple -r options, it was that the way it's done -rubygems
-rsomegem won't work since -r doesn't use the same mechanism as
require so that rubygems doesn't get involved.

I fixed it by having an auxiliary .rb files which require rubygems and
either activesupport or tzinfo and -r requiring that.

Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

More information about the rspec-users mailing list