I have created a spec as subclass of another spec,
and overridden "setup" method of supers.
I have expected super.setup method is not executed.
But, maybe Spock have executed super.setup method in spite of I have
not called super.setup explicitly.
Is it expected Spock work?
If so, could I kill super.setup method action?
I have created a spec like below.
class BaseSpock extends Specification {
def setup() {
println "BaseSpock running..."
}
}
class HelloSpock extends BaseSpock {
@Override
def setup() {
println "HelloSpock running..."
}
def "can you figure out what I'm up to?"() {
expect:
"Spock".size() == 5
}
}
And, System output is here.
------------
T E S T S
------------
Running HelloSpock
BaseSpock running...
HelloSpock running...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.969
sec
Running BaseSpock
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
I use
* groovy 1.7.0
* spock 0.4-groovy-1.7-SNAPSHOT
Regards
Cheers,
Peter
> --
>
> You received this message because you are subscribed to the Google Groups "Spock Framework" group.
> To post to this group, send email to spockfr...@googlegroups.com.
> To unsubscribe from this group, send email to spockframewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/spockframework?hl=en.
>
>
I've not had a concrete problem.
Just, I use base specification class that extends Grails's
"UnitSpecification"(defining setup()), and I was not sure I should
call super.setup() or not when I define my setup() method in the base
specification.
In addition, I had a question about what to do in case I don't need
UnitSpecification.setup() (maybe, such a situation unlikely to be
encountered...).
Thank you,
You don't have to call super.setup(). Actually, we should flag this as
an error, as it would result in the base method being run twice.
> In addition, I had a question about what to do in case I don't need
> UnitSpecification.setup() (maybe, such a situation unlikely to be
> encountered...).
Let us know in case you encounter such a situation. (If you are in
control of the base class, this is easy to achieve: Let the base setup
() method delegate to doSetup(), and override doSetup() in the derived
class. But think twice before doing this. There might be a better
solution to your problem.)
Cheers,
Peter