On 4/07/2014 8:03 pm, Arup Rakshit wrote:
On Friday, July 04, 2014 09:02:59 PM Xavier Shay wrote:
Sorry I don't understand what you are either asking or saying.
> If an object dynamically responds to a message via #method_missing,
*but does not indicate this via #respond_to?*, then this matcher will
give you false results.
Correct. If an object is doing this, it has incorrectly implemented
method_missing.
I would like to understand, why my test passed, as I didn't implement
#respond_to?.
ok my apologies, I understand now.
When you call "define_method", that actually makes the method on the
object, meaning that respond_to? returns true. You can see this by
adding the following line to your spec:
puts subject.respond_to?(:foo)
If you actually just use method_missing and don't define the method,
then the spec will fail:
class Foo
def method_missing(name,*args,&block)
"#{name} has been defined dynamically"
end
end
Hope that helps,
Xavier
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/53B77B86.5020706%40xaviershay.com.
For more options, visit https://groups.google.com/d/optout.