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
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?
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
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 >
Hi all, I am trying to use autotest with rspec and rais, and it seems to work fine when I run autotest -rails initially, but then autotest fails to recognize file changes and run tests continuously. Did I skip a step? Here is my setup: rails v1.2.3 rspec plugin v1.0.5 rspec_on_rails plugin v1.0.5 ZenTest gem v3.6.1 Thanks for any help with fixing this! Ingo
On 7/27/07, Ingo Weiss <ingo at ingoweiss.com> wrote:> Hi all, > > I am trying to use autotest with rspec and rais, and it seems to work > fine when I run autotest -rails initially, but then autotest fails to > recognize file changes and run tests continuously. Did I skip a step? > Here is my setup: > > rails v1.2.3 > rspec plugin v1.0.5 > rspec_on_rails plugin v1.0.5 > ZenTest gem v3.6.1Leave off -rails. Just type "autotest"> > Thanks for any help with fixing this! > Ingo > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >