tokuhirom/Test-Stub — pull request #1 by belden (2012-12-23 19:34:51+00:00)
Title: Don't allow stub($object)->some_method to work unless $object->can('some_method')

This pull request consists of two parts:

1. Some additional tests to document current behavior.
2. A bug fix

The additional tests are fairly self-explanatory; I added them to be sure I wasn't breaking any existing behavior.

The bug fix is a little subtle. Let's say you have this code:

```perl
sub do_something_with_this_object {
my ($object) = @_;

my $result = $object->stub_mee_otu; # whoops, typo: I meant ->stub_me_out

return uc($result);
}

```

Note that the production code above has a misspelling for what method gets called on $object.

Now assume I have a test for this function:

```perl
my $object = Target->new;

stub($object)->stub_me_out('some random data'); # note that the test correctly affects ->stub_me_out
```

At this point, any test of do_something_with_this_object() will not catch the fact that ->stub_me_out is not being called, and that a typo'd method name is being called instead.

The fix is to check whether the requested method can be reached by the object that is being stub()'ed; if the method can be reached, stubbing continues. If the method can't be reached, the test will terminate with a familiar exception.