Last active
December 22, 2015 00:39
-
-
Save sergiomichels/6390632 to your computer and use it in GitHub Desktop.
I'm not treating Spock nice?
This file contains hidden or 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
| class RecenteControllerSpec extends IntegrationSpec { | |
| def grailsApplication | |
| @Shared | |
| Long formId | |
| def setup() { | |
| formId = null | |
| Usuario usuario = new Usuario(nome: 'Admin', login: 'ADMIN', email: 'inovacao@insoft4.com.br', senha: 'xxx') | |
| assert usuario.save() | |
| def programas = [ | |
| [cod: 'FW001', descr: 'Fusos Horários', chave: 'menu.fw001.mainPanel.title', modulo: 'fw.test'], | |
| [cod: 'FW002', descr: 'Tolerâncias de Acesso', chave: 'menu.fw002.mainPanel.title', modulo: 'fw.test'], | |
| [cod: 'FW003', descr: 'Perfis de Acesso', chave: 'menu.fw003.mainPanel.title', modulo: 'fw.test'], | |
| [cod: 'FW004', descr: 'Tipos de Pessoas', chave: 'menu.fw004.mainPanel.title', modulo: 'fw.test'], | |
| [cod: 'FW005', descr: 'Teste', chave: 'menu.fw005.mainPanel.title', modulo: 'fw.test'] | |
| ] | |
| programas.each { prg -> | |
| Programa programa = new Programa(prg) | |
| assert programa.save(flush: true) | |
| if(!formId) { | |
| formId = programa.id | |
| println "###### formId defined: $formId" | |
| } | |
| } | |
| println "####### formId in the end: $formId" | |
| } | |
| @Unroll | |
| def "test my controller with different ids"() { | |
| given: "The controller..." | |
| def controller = getController() | |
| when: "Calling registrarRecente to the defined id" | |
| println "------> Calling for id: $prog" | |
| SpringSecurityUtils.doWithAuth("ADMIN") { | |
| controller.registrarRecente(prog ? prog : formId) //if I use formId directly it works, why? | |
| } | |
| then: "Response text must be as expected" | |
| assert controller.response.text.contains(sucessoText) | |
| assert controller.response.text.contains(message) | |
| where: | |
| prog | sucessoText | message | |
| formId | '"success":true' | '"data":' | |
| 99 | '"success":false' | '"message":"Record not found."' | |
| //prog << [programaId, 99] tried also... | |
| } | |
| def getController() { | |
| return grailsApplication.mainContext.getBean(RecenteController.class.name) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment