groovy - Unable to mock Grails Service method when unit testing Controller - MissingMethodException -


am getting following error message when testing controller - see below code. how can correct this? when invoke service method controller (run-app) , works fine.

exception:

groovy.lang.missingmethodexception: no signature of method: grails.test.grailsmock.isok() applicable argument types: (java.lang.string) values: [h] @ ...vcontrollerspec.test something(vcontrollerspec.groovy:)

class: vcontrollerspec

import grails.test.mixin.testfor import spock.lang.specification  @testfor(vcontroller) @mock(vservice) class vcontrollerspec extends specification {      void "test something"() {         given:         def vservicemock = mockfor(vservice)         vservicemock.demand.isok { string yeah -> return true }         controller.vservice = vservicemock.createmock()          when:         def iso = vservicemock.isok("h")           then:         iso == true          } } 

class:vservice

import grails.transaction.transactional  @transactional class vservice {     def isok = { string yeah ->              def iso = false         return iso     } } 

thanks, steve

assuming there action in vcontroller as:

def myaction() {     vservice.isok('hello') } 

below test should pass

void 'test service'() {     given:     def vservicemock = mockfor(formatservice)     vservicemock.demand.isok { string yeah -> return true }     controller.vservice = vservicemock.createmock()      when:     def iso = controller.myaction()       then:     iso == true } 

there few things optimize here including using method isok instead of closure best practices.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -