Skip to content

Mock invocation order is based on method return order, not invocation #475

@robfletcher

Description

@robfletcher

Originally reported on Google Code with ID 353

This fails:

   def "spock bug"() {
    given:
    def r1 = Mock(Runnable)
    def r2 = Mock(Runnable)
    def r3 = { r1.run() }

    when:
    r3()

    then:
    1 * r1.run() >> { r2.run() }

    then:
    1 * r2.run()
  }

While this passes:

  def "spock bug"() {
    given:
    def r1 = Mock(Runnable)
    def r2 = Mock(Runnable)
    def r3 = { r1.run() }

    when:
    r3()

    then:
    1 * r2.run()

    then:
    1 * r1.run() >> { r2.run() }
  }

Spock thinks r2.run() was called first because it returned before r1.run().

Reported by luke@gradleware.com on 2014-03-12 21:53:34

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions