Created
June 9, 2012 17:37
-
-
Save ck1125/2901905 to your computer and use it in GitHub Desktop.
Filters with dependencies mocking with Spock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package grails_filter_tests | |
import spock.lang.Specification | |
import org.springframework.beans.factory.config.MethodInvokingFactoryBean | |
import grails.test.mixin.* | |
import grails.test.mixin.support.GrailsUnitTestMixin | |
import grails.test.mixin.web.FiltersUnitTestMixin | |
@TestFor(SimpleController) | |
@TestMixin([GrailsUnitTestMixin,FiltersUnitTestMixin]) | |
@Mock(MySimpleFilters) | |
class MySimpleFiltersSpec extends Specification { | |
def 'show working mock test for filter'() { | |
given: | |
defineBeans { | |
simpleService(MethodInvokingFactoryBean) { | |
targetObject = this | |
targetMethod = "mockSimpleService" | |
arguments = ['hi'] | |
} | |
} | |
when: | |
withFilters(action:"index") { | |
controller.index() | |
} | |
then: | |
request.text == 'hi' | |
response.text == 'hi' | |
} | |
SimpleService mockSimpleService(String text) { | |
SimpleService service = Mock(SimpleService) | |
service.aMethod() >> text | |
0 * service._ | |
return service | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment