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

Request for BehaviorSpec sample #562

Closed
JustinTullgren opened this issue Jan 14, 2019 · 6 comments
Closed

Request for BehaviorSpec sample #562

JustinTullgren opened this issue Jan 14, 2019 · 6 comments
Assignees
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones.

Comments

@JustinTullgren
Copy link
Contributor

Hi,

Version: "io.kotlintest:kotlintest-runner-junit5:3.1.11"
Kotlin Version: 1.3.11

I am curious how to use the And syntax with a BehaviorSpec.

given("a stateful object") {
  `when`("the stateful object is configured with A") {
      victim.setA("foo");
      and("the statefule object is configured with B") {
        victim.setB("bar");
         then("it should print hello") {
          victim.print() shouldBe "hello"
        }
      }
    }
}

When trying to do this the receiver context can't be determined:
Unit can't be called in this context by implicit receiver. Use explicit context if necessary.

Adding the context this@given.and does not resolve the issue and the test context is never executed.

I couldn't find a concrete example.

Thanks!

@sksamuel
Copy link
Member

And can only be used at the given scope.
We should probably allow it inside the when scope too.
@Kerooker an easy one ?

@LeoColman
Copy link
Member

The problem to do it in the When scope is when will it stop? We were discussing this earlier today hahah

Given("A") {
    And("B") {
        And("C") {
            And("D") {
                When("E"){
                    And("F"){
                        And("G"){

                         }
                    }
                }
           }
        }
    }
}

But maybe this is users' choice?

@LeoColman LeoColman added the enhancement ✨ Suggestions for adding new features or improving existing ones. label Jan 15, 2019
@sksamuel
Copy link
Member

If you want to go crazy why not.
No difference to using free spec and nesting 200 times.

LeoColman added a commit that referenced this issue Jan 18, 2019
To improve BehaviorSpec customizability, this commit adds extra scopes to BehaviorSpec. As discussed, users can concatenate `And` indefinitely, but it's ok. As `And` is optional to complete a test. This behavior is also observed in `FreeSpec`, as it can concatenate infinite test scopes too.

To do that, every context (Given, And/When and Then) receive a new possibility of scoping, `And`. There are some variations of it, to build tests correctly: GivenAndContext, WhenAndContext and ThenAndContext. All of these are optional to use.

Fixes #562
LeoColman added a commit that referenced this issue Jan 18, 2019
To improve BehaviorSpec customizability, this commit adds extra scopes to BehaviorSpec. As discussed, users can concatenate `And` indefinitely, but it's ok. As `And` is optional to complete a test. This behavior is also observed in `FreeSpec`, as it can concatenate infinite test scopes too.

To do that, every context (Given, And/When and Then) receive a new possibility of scoping, `And`. There are some variations of it, to build tests correctly: GivenAndContext, WhenAndContext and ThenAndContext. All of these are optional to use.

Fixes #562
@LeoColman LeoColman self-assigned this Jan 18, 2019
@LeoColman
Copy link
Member

@JustinTullgren
Please take a look at #593 and see if it suits you correctly.

LeoColman added a commit that referenced this issue Jan 18, 2019
To improve BehaviorSpec customizability, this commit adds extra scopes to BehaviorSpec. As discussed, users can concatenate `And` indefinitely, but it's ok. As `And` is optional to complete a test. This behavior is also observed in `FreeSpec`, as it can concatenate infinite test scopes too.

To do that, Given and And/When contexts received a new possibility of scoping, `And`. There are some variations of it, to build tests correctly: GivenAndContext and WhenAndContext. All of these are optional to use.

Fixes #562
LeoColman added a commit that referenced this issue Jan 18, 2019
To improve BehaviorSpec customizability, this commit adds extra scopes to BehaviorSpec. As discussed, users can concatenate `And` indefinitely, but it's ok. As `And` is optional to complete a test. This behavior is also observed in `FreeSpec`, as it can concatenate infinite test scopes too.

To do that, Given and And/When contexts received a new possibility of scoping, `And`. There are some variations of it, to build tests correctly: GivenAndContext and WhenAndContext. All of these are optional to use.

Fixes #562
@JustinTullgren
Copy link
Contributor Author

@Kerooker fast turnaround! That works just fine thanks!

@LeoColman
Copy link
Member

It might get released soonish.
We will just fix a bug in another part of the framework and this might go along with it

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

3 participants