[rspec-devel] [ rspec-Patches-14254 ] Improved error handling for Object#should and Object#should_not

noreply at rubyforge.org noreply at rubyforge.org
Tue Oct 2 18:28:16 EDT 2007


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

Category: None
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 3
Submitted By: Antti Tarvainen (tarvaina)
>Assigned to: David Chelimsky (dchelimsky)
Summary: Improved error handling for Object#should and Object#should_not

Initial Comment:
This patch improves the error handling of Object#should and Object#should_not methods. It does two things:

1. It causes an InvalidMatcherError to be raised when something else besides a matcher is given to a should expression as a parameter. Before the patch, the type of exception depended on context and was either NoMethodError or ExpectationNotMetError, depending on the context.

2. It catches cases where a nil parameter is given as a matcher. (There was a pending example in the specs for this one.)


Note that cases where no matcher argument is given to a should expression are not caught and will continue to give no warnings. I made a pending example for this but I doubt there's a way to solve it.

Summarising:

# These all will now raise InvalidMatcherError
object.should 5
object.should false
object.should nil
object.should eql?("foo")
object.should_not 5
object.should_not false
object.should_not nil
object.should_not eql?("foo")

# As before, these will pass without a warning
object.should
object.should_not


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

>Comment By: David Chelimsky (dchelimsky)
Date: 2007-10-02 22:28

Message:
Applied to r2686.

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

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


More information about the rspec-devel mailing list