Created
April 25, 2019 11:19
-
-
Save mutyonok/609373367161a0281a494863f4778a2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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