Skip to content

Groovy Mocks do not support isProperty() style getters for booleans #1270

@mlasevich

Description

@mlasevich

Related, (but not the same as) #1256

When testing using a GroovyMock/GroovyStub/GroovySpy - isProperty() style getters are not respected, and only getProperty() is used.

Tested under org.spockframework:spock-core:1.3-groovy-2.4

To reproduce:

import spock.lang.Specification

class TesterSpec extends Specification {

  static class Tester {

    boolean isEnabled() {
      return true
    }
  }

  def 'Works'() {
    given:
      Tester x = new Tester()
    expect:
      x.enabled == true
  }

  def 'GroovySpy does not work Test'() {
    given:
      Tester x = GroovySpy(Tester)
    expect:
      x.enabled == true
  }

  def 'GroovyMock does not work either Test'(){
    given:
      Tester x = GroovyMock(Tester)
    when:
      x.enabled
    then:
      1 * x.isEnabled() >> true
  }

  def 'Mock works though Test'(){
    given:
      Tester x = Mock(Tester)
    when:
      x.enabled
    then:
      1 * x.isEnabled() >> true
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions