Partial mocking

I need partial mocking:

class Post
def meth1; meth2; end
def meth2; nil; end
end

real_model = Post.new
mock_model = SomeMock.new real_model
mock_model.expect :meth1, true
mock_model.validate
mock_model.verify # should return true if #meth2 has worked and false
otherwise

There is SimpleMock (https://github.com/tatey/simple_mock) but seems it
doesn’t accept partial mocking:
https://github.com/tatey/simple_mock/issues/3

Can you help me? Thanks

On Oct 2, 2013, at 12:43 , Alexander K. [email protected]
wrote:

I need partial mocking:

Need? Nobody needs mocking, partial or otherwise.

otherwise

There is SimpleMock (https://github.com/tatey/simple_mock) but seems it
doesn’t accept partial mocking:
https://github.com/tatey/simple_mock/issues/3

I don’t see any need for mocks here at all:

real_model = Post.new

def real_model.valid?
true
end

real_model.validate

… assert things about the state of the model

Better, don’t override valid? at all and just test your Post instance
directly.

On Oct 2, 2013, at 15:20 , Tamara T. [email protected]
wrote:

On Oct 2, 2013, at 3:57 PM, Ryan D. [email protected] wrote:

On Oct 2, 2013, at 12:43 , Alexander K. [email protected] wrote:
Need? Nobody needs mocking, partial or otherwise.

I can think of quite a few people that need to be mocked immediately.

That’s… different.

On Oct 3, 2013 4:57 PM, “Ryan D.” [email protected] wrote

That’s… different.

That’s what she said.

On Oct 2, 2013, at 3:57 PM, Ryan D. [email protected] wrote:

On Oct 2, 2013, at 12:43 , Alexander K. [email protected] wrote:
Need? Nobody needs mocking, partial or otherwise.

I can think of quite a few people that need to be mocked immediately.

UPDATE: I need this: https://github.com/rr/rr#proxies. But I want not RR
but know how is https://github.com/rr/rr#proxies implemented…

Ryan, I didn’t understand you, sorry. I should validate if some method
has been called (maybe from another method). How can I do this?

I think I can create a boolean instance variable that is false at begin.
And redefine method I want to validate: it sets this variable to true.
Validate method returns this variable.

But are there some automated mechanisms/tools? Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs