Skip to content

Instantly share code, notes, and snippets.

@marcingrzejszczak
Created February 17, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcingrzejszczak/6c8067edae50e82db322 to your computer and use it in GitHub Desktop.
Save marcingrzejszczak/6c8067edae50e82db322 to your computer and use it in GitHub Desktop.
Calling assertion block from where
class AssertionFromWhereSpec extends Specification {
def 'should execute closure from where'() {
given:
Dupa dupa = Mock()
Cyce cyce = new Cyce(dupa)
when:
cyce.asd()
then:
1 * dupa.cosTam(*_) >> { args ->
assertion(args[1])
return 1
}
where:
var1 | assertion
'asd' | { int value -> assert value > 100 }
}
class Cyce {
private Dupa dupa
Cyce(Dupa dupa) {
this.dupa = dupa
}
int asd() {
return dupa.cosTam('a', 123)
}
}
interface Dupa {
int cosTam(String a, Integer b)
}
class DupaImpl implements Dupa {
int cosTam(String a, Integer b) {
return 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment