If anyone else is looking to solve this formatting issue, I installed the Spock Eclipse Plugin from here:
http://marketplace.eclipse.org/content/spock-plugin#.UtWI_GTF3VQ
and was subsequently all set formatting-wise!
Question
Eclipse is formatting my Spock tests like this:
def "Trivial example"() {
setup:
def consoleMock = Mock(TestConsole) {
1 * readLine('provide input 1: ') >> 'response 1'
1 * readLine('provide input 2: ') >> 'response 2'
1 * readLine('provide input 3: ') >> 'response 3'
}
processor.inputMethods.cons = consoleMock
when:
def testResult1 = processor.getInput(1, 'provide input 1: ')
def testResult2 = processor.getInput(2, 'provide input 2: ')
def testResult3 = processor.getInput(3, 'provide input 3: ')
then:
testResult3 == 'response 3'
noExceptionThrown()
}
I would like to have them formatted like this:
def "Trivial example"() {
setup:
def consoleMock = Mock(TestConsole) {
1 * readLine('provide input 1: ') >> 'response 1'
1 * readLine('provide input 2: ') >> 'response 2'
1 * readLine('provide input 3: ') >> 'response 3'
}
processor.inputMethods.cons = consoleMock
when:
def testResult1 = processor.getInput(1, 'provide input 1: ')
def testResult2 = processor.getInput(2, 'provide input 2: ')
def testResult3 = processor.getInput(3, 'provide input 3: ')
then:
testResult3 == 'response 3'
noExceptionThrown()
}
I can not get the formatter to do so. The only way I have found is to format it correctly by hand and then insert @formmatter:off/@formatter:on tags. Without the tags Eclipse reformats to the first version [I need to have formatting on at Save time for other reasons.] Not only is this ugly, it doesn't scale very well across hundreds of tests! Is a better way possible?
Finally, sorry for asking such a non-technical question, but as can be seen above, the formatting really does affect readability and I can't figure it out!
La solution
If anyone else is looking to solve this formatting issue, I installed the Spock Eclipse Plugin from here:
http://marketplace.eclipse.org/content/spock-plugin#.UtWI_GTF3VQ
and was subsequently all set formatting-wise!