Skip to content

Instantly share code, notes, and snippets.

View mario-rezende-ifood's full-sized avatar

Mario Rezende mario-rezende-ifood

  • iFood
  • Sao Paulo / Brazil
View GitHub Profile
then:
name == 'Fulano'
name != 'Beltrano'
age >= 20
age < 100
def 'Allow user access only for 18 over'(name, age, expected) {
given: 'user entity'
def user = new User(name, age)
when: 'validate user access'
def userCanAccess = AccessService().grantUser(user)
then:
userCanAccess == expected
def 'Maximum of two numbers'() {
expect:
Math.max(a, b) == c
where:
a | b | c
1 | 3 | 3
7 | 4 | 4
0 | 0 | 0
Condition not satisfied:
Math.max(a, b) == c
| | | | | |
| 7 7 4 | 4
| false
class java.lang.Math
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
@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
@Test
void validateUserRegistration() {
// setup
String name = "Fulano"
int age = 20
String email = "fulano@mail.test"
// execute
User user = UserService().register(name, age, email)
def 'Validate user registration'() {
given: 'user data'
def name = "Fulano"
def age = 20
def email = "fulano@mail.test"
when: 'register the user'
def user = UserService().register(name, age, email)
given: 'open a database connection'
// code goes here
and: 'seed the customer table'
// code goes here
and: 'seed the product table'
// code goes here
def subscriber1 = Mock(Subscriber)
def subscriber2 = Mock(Subscriber)