Reputation: 45
I have a XXXController that is a subclass of a baseController. I want to test the xxxController and I need to stub one method call from the baseController.
I have tried something like that:
controller.xxxMethod(_) >> false
but It's not working.
Anybody knows how to stub a baseController method call in the subClass using Spock?
Upvotes: 0
Views: 116
Reputation: 8054
You are trying to mock/stub the class under test, which is an anti-pattern. I would tell you to look at Spies and partial mocks (http://spock-framework.readthedocs.org/en/latest/interaction_based_testing.html#partial-mocks) but as you can see, even the official documentation says "Think twice before using this feature."
So my suggestion is to refactor your code where the class under test is a real class and only collaborators are mocked/stubbed.
Upvotes: 1