Minitest - calling a mocked instance method from within another instance method
Minitest - calling a mocked instance method from within another instance method I've come across some weird behavior in Minitest::Mock and can't figure out what's the reason behind it. Minitest::Mock Say I have this class A that has a method b that calls method c : b c class A def b c end def c 1 end end I would like to mock the c method to return 2 instead of 1: c require 'minitest/autorun' a = Minitest::Mock.new(A.new) a.expect(:c, 2) But for some reason b still returns 1: b > a.b => 1 Obviously calling c directly will work: c > a.c => 2 > a.c MockExpectationError: No more expects available for :c: Why is the expectation on c not being invoked when calling it from within the instance? c 1 Answer 1 This is how Minitest::Mock works; the mock object is a wrapper around the "real" instance of A , and defined expectations intercept the...