djcrankypants / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Global GroovyMock aren't cleaned #323

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Given these two Spec :

class FooServiceSpec extends Specification {

     def 'doSomething() should do something'() {
          setup:
          GroovyMock(Bar, global: true)

          when:
          service.do()

          then:
          1 * Bar.life() >> 42
     }
}

class BarSpec extends Specification {

     def 'computeLife() should return 42'() {
          setup:
          def bar = new Bar()

          expect:
          bar.computeLife() == 42
     }
}

If I run my tests and FooServiceSpec is executed before BarSpec, 'computeLife() 
should return 42' fails with a NPE on 'bar.computeLife()'. If FooServiceSpec is 
executed after BarSpec, everything works.

So my guess is that the mocking of the static method 'Bar.life()' is not 
cleaned, so when I do 'new Bar()' it returns null.

FYI, I'm using Spock 0.7-groovy-2.0 with Grails 2.2.3 and spock-grails-support 
0.7

To run the tests in a specific order in do :
    grails test-app -unit FooServiceSpec BarSpec              >>> Fail
    grails test-app -unit BarSpec FooServiceSpec              >>> OK

This is really annoying cause I can't control which test is executed first, so 
my Jenkins randomly fails to build the project.

Original issue reported on code.google.com by gcout...@excilys.com on 29 Jul 2013 at 12:55

GoogleCodeExporter commented 8 years ago
I do have the same issue with GroovySpy and global: true. Though my tests don't 
interfere with each other yet, I get runtime errors on the spied on class when 
Grails creates the test reports.

Is there a way to manually disable the spy/mock during clean-up?

Original comment by goo...@chathub.io on 3 Feb 2014 at 8:17