andrezrv
9/26/2013 - 5:41 PM

How to test with Spock using Build Test Data Plugin for Grails. Spock Docs: http://docs.spockframework.org/ Build Test Data Docs & Repo: h

How to test with Spock using Build Test Data Plugin for Grails. Spock Docs: http://docs.spockframework.org/ Build Test Data Docs & Repo: https://github.com/tednaleid/build-test-data

package myapp.downloads

import grails.test.mixin.TestFor
import spock.lang.Specification
import grails.buildtestdata.mixin.Build

/**
 * See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
 */
@TestFor( Download )
@Build( [ Download ] )
class DownloadSpec extends Specification {

	void "test Download.getFullName() method"() {
		
		// Create some objects to test with.
		def download = Download.build()
		
		given: "Try to get full name for the person associated to the download"
			def result = download.getFullName()
		
		when: "Returned value equals the concatenation of name and lastname"
			download.person.name + ' ' + download.person.lastName == result
		
		then: "Print success message"
			println( '# SUCCESS: Test for Download.getFullName() passed.' )
		
	}
	
}