Skip to content

Instantly share code, notes, and snippets.

Avatar

Mario Rezende mario-rezende-ifood

  • iFood
  • Sao Paulo / Brazil
View GitHub Profile
View exception-stubbing.groovy
subscriber.receive(_) >> { throw new InternalError("ouch") }
View exception-verification.groovy
given:
def stack = new Stack()
when:
stack.pop()
then:
thrown(EmptyStackException)
stack.empty
View stubbing-interaction.bash
subscriber.receive(_) >> "ok"
| | | |
| | | gerador de resposta
| | argumento de restrição
| método de restrição
objeto de restrição
View stubbing-spock.groovy
class Publisher {
private Subscriber subscriber
Publisher(Subscriber subscriber) {
this.subscriber = subscriber
}
String sendAndGetStatus(String message) {
return subscriber.receive(message)
}
View mock-interactions-constrain.bash
1 * subscriber1.receive("hello")
| | | |
| | | restrição de argumento
| | restrição de método
| restrição de alvo
restrição por cardinalidade
View mock-creation-2.groovy
Subscriber subscriber1 = Mock()
Subscriber subscriber2 = Mock()
View mock-creation-1.groovy
def subscriber1 = Mock(Subscriber)
def subscriber2 = Mock(Subscriber)
View mock-examples.groovy
class Publisher {
List<Subscriber> subscribers = []
void send(String message){
subscribers*.receive(message)
}
}
interface Subscriber {
void receive(String message)
}
View max-2-numbers-unroll-output.sh
maximum of 1 and 3 is 3 PASSED
maximum of 7 and 4 is 4 FAILED
Math.max(a, b) == c
| | | | | |
| 7 7 4 | 4
| false
class java.lang.Math
maximum of 0 and 0 is 0 PASSED
View max-2-numbers-unroll.groovy
@Unroll
def 'Maximum of #a and #b is #c'() {
expect:
Math.max(a, b) == c
where:
a | b | c
1 | 3 | 3
7 | 4 | 4