Wednesday, January 6, 2016

Confine metaClass changes to a specific test class or test method in grails

@ConfineMetaClassChanges([StatisticsService])
StatisticsServiceIntegrationTest extends IntegrationSpec {
    StatisticsService statisticsService
    void "count login to private area"() {
        setup:
            def user = new User(statistics: new UserStatistics())
            statisticsService.metaClass.getCurrentUser = { -> user }
        when:
            statisticsService.countLoginPA()
        then:
            user.statistics.logins == 1
    }    
}

http://spockframework.github.io/spock/javadoc/1.0/spock/util/mop/ConfineMetaClassChanges.html

Reset last local git commit

git reset HEAD~1