Forgus / spock

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

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

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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().

Original issue reported on code.google.com by l...@gradleware.com on 12 Mar 2014 at 9:53