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

Is there anything similar to JUnit Test Rule? #118

Closed
fbcbl opened this issue Sep 13, 2016 · 4 comments
Closed

Is there anything similar to JUnit Test Rule? #118

fbcbl opened this issue Sep 13, 2016 · 4 comments

Comments

@fbcbl
Copy link

fbcbl commented Sep 13, 2016

Hello Guys,

I wanted to be able to do something with the behavior similar to the JUnit test rule. Is that possible?

My goal would be to something like:

beforeEach {
   RxJavaPlugins.getInstance().reset()
   RxJavaPlugins.getInstance().registerSchedulersHook(rxJavaSchedulersHook)}
}

afterEach {
  RxJavaPlugins.getInstance().reset()
}

But without the need to repeat this code in each single test and somehow contain this logic on a separate piece of code.

Thank you

@mfulton26
Copy link

I don't think Spek has anything specific for this but you can make your own custom group functions which applies "rules". e.g.:

inline fun Dsl.rxGroup(description: String, pending: Pending = Pending.No,
                       crossinline body: Dsl.() -> Unit) {
    group(description, pending) {
        beforeEach {
            RxJavaPlugins.getInstance().reset()
            RxJavaPlugins.getInstance().registerSchedulersHook(rxJavaSchedulersHook)}
        }
        body()
        afterEach {
            RxJavaPlugins.getInstance().reset()
        }
    }
}

@fbcbl
Copy link
Author

fbcbl commented Sep 13, 2016

Thought so! Awesome tip! 👍

@fbcbl fbcbl closed this as completed Sep 13, 2016
@raniejade
Copy link
Member

Another use case for #115 :)

@christopherperry
Copy link

How would you achieve the same functionality as RuleChain?

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

No branches or pull requests

4 participants