2014-01-13 24 views
0

Eclipse是格式化我的斯波克測試是這樣的:可以在Eclipse/STS中控制格式化Spock規範嗎?

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() 
} 

我想有他們格式如下:

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() 
} 

我無法格式化這樣做。我發現的唯一方法是手動正確格式化,然後插入@formmatter:off/@ formatter:on tags。如果沒有標籤,Eclipse會重新格式化爲第一個版本[我需要在出於其他原因保存時進行格式化。]這不僅是醜陋的,它在數百個測試中不能很好地擴展!是更好的方法嗎?

最後,很抱歉提出這樣一個非技術性的問題,但從上面可以看出,格式化確實會影響可讀性,我無法弄清楚它!

回答

1

如果其他人正在尋找解決這一格式問題,我從這裏安裝了斯波克Eclipse插件:

http://marketplace.eclipse.org/content/spock-plugin#.UtWI_GTF3VQ 

並且隨後是所有設置格式化明智!