simple_mock icon indicating copy to clipboard operation
simple_mock copied to clipboard

Method calls from calls not assert on tracer

Open kuraga opened this issue 11 years ago • 0 comments

Good day, @tatey !

Consider

class Post
  def valid?
    nil
  end

  def validate
    valid?
  end
end

real_model = Post.new
mock_model = SimpleMock.new real_model
mock_model.expect :valid?, true
mock_model.validate # => nil
mock_model.verify # => raises MockExpectationError

Yes, the old method has been called. Tracer didn't receive assert call.

A test for this situation is added by #4 . Yes, this situation is absent in docs and tests but I thing it's a non-normal.

I think there is key of this problem (from http://stackoverflow.com/questions/18163877/strange-simpledelegator-behavior/18164211):

require 'delegate'

class Foo < SimpleDelegator
  def meth
    p 'new_meth'
  end
end

class Bar
  def meth
    p 'old_meth'
  end

  def bar_meth
    meth
  end
end

bar = Bar.new
foo = Foo.new(bar)
foo.meth      #=> "new_meth"
foo.bar_meth  #=> "old_meth"

New method has been called straight. But old method has been called from other call.

What do you think? Thanks!

kuraga avatar Aug 11 '13 09:08 kuraga