[rspec-users] File.stub!
David Chelimsky
dchelimsky at gmail.com
Fri Jul 27 09:35:21 EDT 2007
On 7/27/07, tim.watson at bt.com <tim.watson at bt.com> 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: tim.watson at bt.com
> Cell: +44 7918 711 612
>
>
> -----Original Message-----
> From: rspec-users-bounces at rubyforge.org
> [mailto:rspec-users-bounces at rubyforge.org] On Behalf Of
> tim.watson at bt.com
> Sent: 27 July 2007 08:27
> To: rspec-users at 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 at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
More information about the rspec-users
mailing list