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

Around advice in the spec DSL #794

Closed
sksamuel opened this issue May 29, 2019 · 13 comments
Closed

Around advice in the spec DSL #794

sksamuel opened this issue May 29, 2019 · 13 comments
Assignees
Labels
enhancement ✨ Suggestions for adding new features or improving existing ones. framework 🏗️ Pertains to the core structure and components of the Kotest framework.
Milestone

Comments

@sksamuel
Copy link
Member

class MyTest : WordSpec() {
  private val manager = ...
  override fun aroundTest(test: () -> TestResult) { 
    manager.transaction.begin()
    test()
    manager.transaction.commit()
  }
}
@sksamuel
Copy link
Member Author

@Kerooker ?

@LeoColman
Copy link
Member

LeoColman commented May 29, 2019 via email

@sksamuel
Copy link
Member Author

Yes, we just need to make Spec itself have a aroundTest and aroundSpec method which create an extension and register it. No-op by default. Like we do for the other spec methods which just delegate as a listener.

@LeoColman
Copy link
Member

Do we want to add more things to the spec class?

I believe this can be delegated to a listener that has a beforeTest and afterTest, without the need to add another construct. What do you think?

@sksamuel
Copy link
Member Author

sksamuel commented May 29, 2019 via email

@LeoColman
Copy link
Member

Similar to the constantNow listeners, it runs beforeTest and afterTest, isn't that what we kinda want?

@sksamuel
Copy link
Member Author

sksamuel commented May 29, 2019 via email

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

I think we can do that with listeners, can't we?

@sksamuel
Copy link
Member Author

sksamuel commented Sep 4, 2019

Now without creating the variables outside of the before / after scopes.

@sksamuel sksamuel self-assigned this Sep 4, 2019
@sksamuel sksamuel added this to the 4.0 milestone Sep 4, 2019
@sksamuel
Copy link
Member Author

sksamuel commented Sep 4, 2019

This can be easily done with the new DSL.

@sksamuel sksamuel added the framework 🏗️ Pertains to the core structure and components of the Kotest framework. label Sep 4, 2019
@sksamuel
Copy link
Member Author

Question/todo: add extension callbacks to the new DSL like the other callbacks.

@sksamuel
Copy link
Member Author

sksamuel commented Jan 16, 2020

I had a little play with this:

eg

   aroundTest { runtest ->
      println("Starting test")
      runtest {
         println("After test")
      }
   }

@sksamuel
Copy link
Member Author

Now in master.

@sksamuel sksamuel mentioned this issue Jan 16, 2020
88 tasks
@sksamuel sksamuel changed the title Would be handy to have "around advice" directly in the spec class Around advice in the spec DSL Jan 16, 2020
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. framework 🏗️ Pertains to the core structure and components of the Kotest framework.
Projects
None yet
Development

No branches or pull requests

2 participants