[rspec-devel] [ rspec-Patches-14152 ] Output warning when method is defined on a nil object.

noreply at rubyforge.org noreply at rubyforge.org
Sat Sep 22 15:18:49 EDT 2007


Patches item #14152, was opened at 2007-09-22 18:35
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=14152&group_id=797

Category: None
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Ian Leitch (idl)
Assigned to: Nobody (None)
Summary: Output warning when method is defined on a nil object.

Initial Comment:
This patch causes define_expected_method to output a warning when a method is defined on a nil object.

This patch allows me to quickly resolve failing specs caused by typos.

e.g.:

before do
  @obj = mock('some object')
  @ob.stub!(:do_stuff)
end

it "should do something" do
    some_trigger
end

This will result in:

Warning: 'do_stuff' defined on a nil object at foo.rb:123.

This patch highlights some nil object stubs in the rspec's own specs. Most appear to be where the author hasn't bothered to use the method created in the before block (or not realized they were referencing a nil object). Although, one case identified in passing_mock_argument_constraints_spec.rb is where the "handling non-constraint arguments" behavior does not define 'it_should_behave_like "mock argument constraints"'.

Cheers
Ian

----------------------------------------------------------------------

>Comment By: Ian Leitch (idl)
Date: 2007-09-22 19:18

Message:
By the way, if you accept this patch I'll go ahead and fix
all the warnings in rspec's specs.

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3151&aid=14152&group_id=797


More information about the rspec-devel mailing list