Cannot use stubbed methods in cleanup method if the test succeeds #616

Open
prismec opened this Issue Jul 13, 2016 · 3 comments

Projects

None yet

3 participants

@prismec
prismec commented Jul 13, 2016 edited

Issue description

I'm trying to use a stubbed method in a cleanup method. This works if an assertion failed in the test, but not if the test succeeds.

How to reproduce

class UseStubInCleanupSpec extends Specification {

    def mock = Mock(java.util.function.Function)

    def setup() {
        mock.apply("a") >> { "b" }
    }

    def cleanup() {
        assert mock.apply("a") == "b"
    }

    def "run a successful test"() {
        expect:
        true
    }

    def "run a failing test"() {
        expect:
        false
    }

}

Java/JDK

1.8

Groovy version

2.3.10:indy

Operating System

Mac

IDE

IntelliJ

Gradle/Grails

compile 'org.spockframework:spock 1.0-groovy-2.3'
@leonard84
Contributor

What would be the usecase for this?

@prismec
prismec commented Sep 5, 2016

The usecase is that the component under test should be shutdown during cleanup but a component that is referenced by the component under test is stubbed and used during shutdown.

@JetyCZ
JetyCZ commented Dec 14, 2016

I would wish that stubbed methods work in cleanup too.

My usecase is, that in cleanup of all my test extending my AbstractMockMvcControllerTest, I render HTML output of the tested controller (which helps me to visually check if view was rendered ok during development). Controller is tested using MockMvc Spring class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment