[mocha-developer] mocking missing methods

James Mead jamesmead44 at gmail.com
Mon Apr 30 15:37:13 EDT 2007


On 28/04/07, David Chelimsky <dchelimsky at gmail.com> wrote:
>
> I love the syntax, though I'd make it a command rather than a
> "state"-ment:
>
> # instance methods
> sheep = mock
> sheep.restrict_to Sheep.instance_methods
>
> # class methods
> sheep = mock
> sheep.restrict_to Sheep.singleton_methods
>
> The other problem is related to Dan's initial point about classes that
> are extended or modified at runtime. If you just pass an Array to
> #restrict_to then it has no knowledge of the type we're interested in,
> so methods added downstream wouldn't be discoverable. With that in
> mind, I propose:
>
> # instance methods
> sheep = mock
> sheep.restrict_to Sheep, :instance_methods
>
> # class methods
> sheep = mock
> sheep.restrict_to Sheep, :singleton_methods
>
> That keeps the readability Jay proposes and supports the late binding
> we're looking for.
>
> More thoughts?
>

As I explained in my reply to Jay's email, I think #respond_to? is the
better method to think about than any of the method-listing methods like
#instance_methods. I know your last suggestion doesn't actually use those
method-listing methods, but it does use that terminology which I think I'd
like to avoid. Do you see what I'm getting at?
-- 
James.
http://blog.floehopper.org


More information about the mocha-developer mailing list