Problems with rspec 1.1 required inside rake tasks

This is interesting.

The default rspec rake tasks generated by Hoe give you an rspec.rake
file that looks like:

begin
require ‘spec’
rescue LoadError
require ‘rubygems’
require ‘spec’
end

So far so good.

When you invoke rake to do something, say check_manifest

rake check_manifest

You wind up with a Runtime error, as follows:

spec.rb:20:in `run’
from /usr/local/lib/ruby/gems/1.8/gems/rspec-1.1.1/lib/
spec.rb:34
from /usr/local/bin/rdebug:19

Note that the spec runner is trying to load ‘check_manifest’, the
argument to rake…

The reason is that rspec-1.1.1/lib/spec.rb’s at_exit hook is being
invoked by, I presume, require ‘spec’

Is there a better way to require rspec (this worked fine in 1.0.8 and
recent trunks), or should I be filing a bug?

Thanks,

Matt


Matt P. | Design & Code
| http://www.reprocessed.org/

On Jan 8, 2008, at 10:55 AM, Matt P. wrote:

spec.rb:20:in `run’

Is there a better way to require rspec (this worked fine in 1.0.8 and
recent trunks), or should I be filing a bug?

I think it is some weird bug, and the solution that I am using until
it is resolved is to do this add this to my rake task.

module Spec
class << self; def run; false; end; end
end

On 8 Jan 2008, at 17:01, Bryan L. wrote:

Is there a better way to require rspec (this worked fine in 1.0.8 and
recent trunks), or should I be filing a bug?

I think it is some weird bug, and the solution that I am using until
it is resolved is to do this add this to my rake task.

module Spec
class << self; def run; false; end; end
end

I solved it by changing the require stanza:

begin
require ‘spec’
rescue LoadError
require ‘rubygems’
require ‘spec’
end
begin
require ‘spec/rake/spectask’
rescue LoadError

to:

begin
require ‘spec/rake/spectask’
rescue LoadError
require ‘rubygems’
gem ‘rspec’
end
begin
require ‘spec/rake/spectask’
rescue LoadError

(Based on the rspec.rake Hoe / newgem threw in)

That does the trick, rake spec still works, and I can run other rake
tasks without explosions.

I’d still like to know whether this is a bug or if there’s a change
in require best practice…

I’ll file a bug if it is…

Matt


Matt P. | Design & Code
[email protected] | http://www.reprocessed.org/