Forum: RSpec Can I run the same specs with different gems? Ideas?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rick D. (Guest)
on 2009-05-15 21:21
(Received via mailing list)
I have a new icalendar Ruby library/gem which is implemented so as
require an implementation of the TZInfo::Timezone class, but not to
care whether that implementation comes from the tzinfo gem, or the
activesupport gem in rails.  It also will make use of the TimeWithZone
class in recent versions of activesupport if it's loaded, but it
leaves the decision of whether to load the activesuport or tzinfo gems
up to the user.

Now, it that makes sense I'd like to be able to run my specs with the
tzinfo gen and then with the activesupport gem.  Ideally I'd like to
have rake tasks like

rake spec:tzinfo
rake spec:activesupport
rake spec:both

The problem is that I think I need something like the fork option for
spec task similar to the one in the cucumber task, since once loaded I
can't unload one or the other gem in the same ruby process.

Is there a trick I'm missing?

--
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
David C. (Guest)
on 2009-05-17 11:34
(Received via mailing list)
On Fri, May 15, 2009 at 11:50 AM, Rick DeNatale
<removed_email_address@domain.invalid> wrote:
> have rake tasks like
>
> rake spec:tzinfo
> rake spec:activesupport
> rake spec:both
>
> The problem is that I think I need something like the fork option for
> spec task similar to the one in the cucumber task, since once loaded I
> can't unload one or the other gem in the same ruby process.
>
> Is there a trick I'm missing?

Sounds like a missing feature, actually. RSpec's own suite has a
forker, which I'm pretty sure that Aslak wrote and is likely the
source of the cucumber option you're talking about, but it is not
exposed as an API, yet. I think it should be. Wanna patch it?
Rick D. (Guest)
on 2009-05-17 17:49
(Received via mailing list)
On Sat, May 16, 2009 at 11:57 AM, David C. 
<removed_email_address@domain.invalid>
wrote:
>> can't unload one or the other gem in the same ruby process.
>>
>> Is there a trick I'm missing?
>
> Sounds like a missing feature, actually. RSpec's own suite has a
> forker, which I'm pretty sure that Aslak wrote and is likely the
> source of the cucumber option you're talking about, but it is not
> exposed as an API, yet. I think it should be. Wanna patch it?

Well, I looked it, and it seems that the RSpec spectask does in fact
run rspec in a separate process using the system command.

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.




--
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
Rick D. (Guest)
on 2009-05-17 20:02
(Received via mailing list)
On Sun, May 17, 2009 at 9:46 AM, Rick DeNatale 
<removed_email_address@domain.invalid>
wrote:

>
> 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
This topic is locked and can not be replied to.