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

Given / when / then style on one indentation level #2209

Closed
dave08 opened this issue Apr 18, 2021 · 2 comments
Closed

Given / when / then style on one indentation level #2209

dave08 opened this issue Apr 18, 2021 · 2 comments
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.

Comments

@dave08
Copy link
Contributor

dave08 commented Apr 18, 2021

It would be nice to not have to nest given/and/when/and/then/and to such levels, while still keeping test setup and running in the corresponding sections, similar to how Spock does things.

Initial proposition (not the cleanest, but at least an idea):

given("qweqwe") { // 'this' is a GivenContext with a var for fixtures
    fixture[1] = RepoStub()
    fixture[0] = SutClass(fixture[1])
}.and("ssrsrrt") { // 'this' is a GivenContext with a var for fixtures
  ...
}.when("qeqw") { // 'this' is a WhenContext with the fixtures in GivenContext and a result var
    result = fixture[0].methodUnderTest()
}.and("ssrsrrrrst") { // 'this' is a WhenContext with the fixtures in GivenContext and a result var
  ...
}.then("werewr") { // 'this' has all the above 
    result shouldBe fixture[1].stubValue
}.and("ssrsrrrrrst") { // 'this' has all the above
    result shouldNotBe fixture[1].stubValue2
}
@dave08 dave08 added the enhancement ✨ Suggestions for adding new features or improving existing ones. label Apr 18, 2021
@dave08
Copy link
Contributor Author

dave08 commented Apr 18, 2021

It could be easier if the given contains the rest, then the main fixtures can be initialized (but then an and on the given would still be nested... unless the and would contain the rest?):

// Not bad:
given("qweqwe") { // 'this' is a GivenContext with a var for fixtures
    val repoStub = RepoStub()
    val sut = SutClass(repoStub)
    
     when("qeqw") { // 'this' is a WhenContext with the fixtures in GivenContext and a result var
          result = sut.methodUnderTest()
      }.and("ssrsrrrrst") { // 'this' is a WhenContext with the fixtures in GivenContext and a result var
        ...
      }.then("werewr") { // 'this' has all the above 
          result shouldBe repoStub.stubValue
      }.and("ssrsrrrrrst") { // 'this' has all the above
          result shouldNotBe repoStub.stubValue2
      }
}
// ... ?
given("qweqwe") { // 'this' is a GivenContext with a var for fixtures
    fixture[1] = RepoStub()
    fixture[0] = SutClass(fixture[1])
}.and("ssrsrrt") { // 'this' is a GivenContext with a var for fixtures
    // some more setting up...

     when("qeqw") { // 'this' is a WhenContext with the fixtures in GivenContext and a result var
          result = fixture[0].methodUnderTest()
      }.and("ssrsrrrrst") { // 'this' is a WhenContext with the fixtures in GivenContext and a result var
        ...
      }.then("werewr") { // 'this' has all the above 
          result shouldBe fixture[1].stubValue
      }.and("ssrsrrrrrst") { // 'this' has all the above
          result shouldNotBe fixture[1].stubValue2
      }
}

@stale
Copy link

stale bot commented Jun 17, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 17, 2021
@stale stale bot closed this as completed Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.
Projects
None yet
Development

No branches or pull requests

1 participant