spockframework / spock

The Enterprise-ready testing and specification framework.
https://spockframework.org
Apache License 2.0
3.54k stars 466 forks source link

ruby style test double support #436

Closed robfletcher closed 9 years ago

robfletcher commented 9 years ago

Originally reported on Google Code with ID 314

Currently there are 2 ways I know of for creating a mock in Spock.
A a = Mock()
def b = Mock(B)

The annoying thing with this approach is that it only works for existing types. Yet
Groovy is a dynamic language so leaving out the type is a valid programming style but
completely unsupported by most mocking libraries I know of.

In ruby you can do the following:

def a = double("a")
a.should_receive(:msg)

So I'd like to be able to do something similar in Spock. E.g:
def a = Mock("a")
1 * a.msg()

Reported by sgo@thinkerit.be on 2013-05-29 14:15:25

robfletcher commented 9 years ago
See "Groovy Mocks" in the reference documentation (http://docs.spockframework.org/en/latest/interaction_based_testing.html#groovy-mocks-new-in-0-7).

Reported by pniederw on 2013-05-29 14:18:37

robfletcher commented 9 years ago
Awesome. So I can do def a = GroovyMock(Object)
Thanks, and sorry for unnecessarily raising an issue.

Reported by sgo@thinkerit.be on 2013-05-29 14:24:22

robfletcher commented 9 years ago
No problem. Let us know how Groovy mocks are working for you. We may eventually support
`def a = GroovyMock()`, but it's not there yet.

Reported by pniederw on 2013-05-29 14:30:46