Mixing interactions and conditions while using Spy

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Mixing interactions and conditions while using Spy

Serban Iordache
Hi,

Please take a look at the following code. It has 3 tests, which only differ in their then: blocks. The first test checks a condition, the second one an interaction and the third one both the condition and the interaction. The third test fails.

import spock.lang.Specification

class SpyTest extends Specification {
 
static class Square {
   
double getLength() {32}

   
public double getArea() {
     
return getLength() * getLength();
   
}
 
}

 
def "check condition with stubbed length"() {
   
def square = Spy(Square) { getLength() >> 10 }
   
when:
   
def area = square.area
   
then:
    area
== 100
  }

 
def "check interaction with stubbed length"() {
   
def square = Spy(Square) { getLength() >> 10 }
   
when:
   
def area = square.area
   
then:
   
2 * square.getLength()
 
}

 
def "check interaction and condition with stubbed length"() {
   
def square = Spy(Square) { getLength() >> 10 }
   
when:
   
def area = square.area
   
then:
   
2 * square.getLength()
    area
== 100
  }
}



The third test fails with the following message:

Condition not satisfied:

area
== 100
|    |
|    false
1024.0



Is this a bug or the expected behavior?

Thanks!

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Loading...