Skip to content

Instantly share code, notes, and snippets.

@ldaley
Forked from pniederw/TheSpockQuiz.groovy
Created March 24, 2010 03:20
Show Gist options
  • Save ldaley/341949 to your computer and use it in GitHub Desktop.
Save ldaley/341949 to your computer and use it in GitHub Desktop.
Spock For Non-Believers
Which code would you rather want to read, write, and maintain? Choose the right answer and win a trip to Vulcan!
A. B.
/* Seven lines of imports removed for clarity */ /* Zero lines of imports removed for clarity */
@RunWith(Parameterized.class) class HelloSpock extends spock.lang.Specification {
public class HelloSpock { def "length of Spock and friends"() {
private String name; expect:
private int length; name.length() == length
public HelloSpock(String name, int length) { where:
this.name = name; name | length
this.length = length; "Spock" | 5
} "Kirk" | 4
"Scotty" | 6
@Test }
public void lengthOfSpockAndFriends() { }
assertEquals(length, name.length());
}
@Parameters
public static List<Object[]> data() {
return Arrays.asList(new Object[][]
{{"Spock", 5}, {"Kirk", 4}, {"Scotty", 6}});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment