Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mlasevich opened this issue Jan 30, 2021 · 1 comment · Fixed by #1302
Closed

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

mlasevich opened this issue Jan 30, 2021 · 1 comment · Fixed by #1302

Comments

@mlasevich
Copy link

mlasevich commented Jan 30, 2021

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
  }
}
@kriegaex
Copy link
Contributor

Like I said in the other issue, the same thing happens in Spock 2.0-M4 and in the master branch after #1256 was merged in already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants