On 7/27/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've answered my own question. I changed before :all do; to just before
> do (which is the same as before :each do) and everything works fine. I'm
> not overly concerned that stubbing has to occur prior to each example
> method, but why is this the case? If this behaviour is intended (which
> I'm guessing it is), then perhaps this should make its way into the
> docs?

There's an open RFE to deal w/ better integrating before(:all) with
everything else:

http://rubyforge.org/tracker/?func=detail&group_id=797&aid=10696&atid=3152

>
> Tim Watson
> Technologist
> BT Web21C SDK
> Email:  [EMAIL PROTECTED]
> Cell:   +44 7918 711 612
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> [EMAIL PROTECTED]
> Sent: 27 July 2007 08:27
> To: rspec-users@rubyforge.org
> Subject: Re: [rspec-users] File.stub!
>
> Hi,
>
> I'm trying to stub File.open and whenever I do, rspec blows up with the
> following error message (undefined method `add' for nil:NilClass), which
> seems to happen because method __add in class Proxy is calling #add on
> global $rspec_mocks, which in turn is nil.
>
> Can someone explain what I'm doing wrong, as I can't seem to stub
> anything out! Here's my code:
>
> class Foo
>     def Foo.open( name, mode )
>         return name
>     end
> end
>
> describe Something, 'blah blah' do
>
>     class FooDouble #:nodoc:
>         attr_reader :data
>         def initialize
>             @data = []
>         end
>         def method_missing( name, *args )
>             puts "ignoring call to #{name} with args [#{args.each |arg|
> arg.inspect}]"
>         end
>         def <<(raw_data)
>             @data.push raw_data
>         end
>     end
>
>     before :all do
>         Foo.stub!( :open ).and_return( FooDouble.new )
>           #have also tried and_return { FooDouble.new }
>     end
>
>     ...
> end
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to