Skip to content

Instantly share code, notes, and snippets.

@mutyonok
Created April 25, 2019 11:19
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 mutyonok/609373367161a0281a494863f4778a2a to your computer and use it in GitHub Desktop.
Save mutyonok/609373367161a0281a494863f4778a2a to your computer and use it in GitHub Desktop.
import spock.lang.Specification
class CodeConstraintVerificationSpec extends Specification {
def repository = Mock(List)
def service = new Service(repository)
def "failing test"() {
given:
def entity = new Entity(events: ['test'])
when:
service.save(entity)
then:
1 * repository.add({ Entity e ->
println(e.events)
e.events.any { it == 'test' }
} as Entity)
}
static class Service {
List<Entity> repository
Service(List<Entity> repository) {
this.repository = repository
}
void save(Entity entity) {
repository.add(entity)
}
}
static class Entity {
def events = new ArrayList<>()
}
}
[test]
[test]
[test]
[test]
[test]
Too few invocations for:
1 * repository.add({ Entity e ->
println(e.events)
e.events.any { it == 'test' }
} as Entity) (0 invocations)
Unmatched invocations (ordered by similarity):
1 * repository.add(<Test$Entity@71def8f8 events=[test]>)
One or more arguments(s) didn't match:
0: Condition not satisfied:
e.events.any { it == 'test' }
| | |
| [test] false
<Test$Entity@71def8f8 events=[test]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment