Skip to content

Instantly share code, notes, and snippets.

View fmamud's full-sized avatar
💻

Felipe Mamud fmamud

💻
View GitHub Profile
@fmamud
fmamud / MySpec.groovy
Created October 14, 2016 04:57
Stubbing many returns in Spock Specification
import spock.lang.*
class MySpec extends Specification {
def "should return 1,2,3 respectively when calling size list"() {
given:
List list = Stub()
list.size() >>> [1,2,3]
expect:
@fmamud
fmamud / MySpec.groovy
Created October 14, 2016 04:37
Stubbing Spock Specification
import spock.lang.*
class MySpec extends Specification {
def "should size list return always 3"() {
given:
List list = Stub()
list.size() >> 3
expect:
@fmamud
fmamud / MySpec.groovy
Created October 14, 2016 03:26
Data Table in Spock Specification
import spock.lang.*
class MySpec extends Specification {
def "maximum of two numbers"(int a, int b, int c) {
expect:
Math.max(a, b) == c
where:
a | b | c
@fmamud
fmamud / MySpec.groovy
Created October 14, 2016 03:05
Expect and Setup sections in Spock Specification
import spock.lang.*
class MySpec extends Specification {
def "should return 4 after list sum"() {
setup:
def list = [2, 2]
expect:
4 == list.sum()
@fmamud
fmamud / MySpec.groovy
Created October 13, 2016 21:24
Spock assert error
MySpec > should return 4 after list sum FAILED
Condition not satisfied:
4 == list.sum()
| | |
| [2] 2
false
at MySpec.should return 4 after list sum(MySpec.groovy:15)
1 test completed, 1 failed
@fmamud
fmamud / MySpec.groovy
Last active October 14, 2016 03:50
First method in Spock Specification
import spock.lang.*
class MySpec extends Specification {
def "should return 4 after list sum"() {
given:
List<Integer> list = new ArrayList<>()
when:
list.add(2)
then:
@fmamud
fmamud / MySpec.groovy
Created October 13, 2016 18:53
Spock Specification
import spock.lang.*
class MySpec extends Specification {
// fields
// fixture methods
// feature methods
// helper methods
}
@fmamud
fmamud / MyExtension.groovy
Created August 4, 2016 05:39
Groovy compiler customization with type checking and static compilation
beforeVisitMethod { methodNode ->
println "calling ${methodNode.name}(${methodNode.parameters.join(',')})"
}
afterMethodCall { call ->
if (getTargetMethod(call).name=='plus') {
addStaticTypeError('plus() not allowed',call)
handled = true
}
@fmamud
fmamud / ast.groovy
Last active July 11, 2016 17:22
TDC São Paulo - Palestra: Groovy como você nunca viu
package tdc.groovy.awesome
import groovy.transform.Immutable
import groovy.transform.ToString
// @TypeChecked
// @CompileStatic
@ToString
@Immutable
@fmamud
fmamud / tdc.erl
Created July 6, 2016 14:34
TDC 2016 São Paulo - Palestra: Erlang sem enrolação
-module (tdc).
-export ([printer/0, mysum/1, loop/0]).
printer() ->
io:format("~p~n", ["Bem vindos ao TDC 2016"]).
mysum([]) ->
0;
mysum([H|T]) ->