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

Shared Examples #13

andreareginato opened this issue Oct 3, 2012 · 8 comments

Shared Examples #13

andreareginato opened this issue Oct 3, 2012 · 8 comments


Copy link

Write your thoughts about the "shared examples" best practice.

Copy link

dgm commented Oct 7, 2012

Doesn't this violate the one assertion per test principal? ;) FWIW, I agree with this practices, but just goes to show that the other rule is more of a guideline.

Copy link

I don't believe it violates the 'one assertion rule' by definition. It will depend entirely on how you define your shared example. The intent is to group behavior, so it can include multiple single assertion cases. See for examples of this.

Copy link

The GOOD example is missing the actual shared examples, so this code doesn't make sense unless someone knows how shared examples work.

Copy link

iRet commented Sep 18, 2014

@gavingmiller absolutely right. Shared examples definition part is missing. It is confusing.

Copy link

georgeu2000 commented Mar 8, 2019

@gavingmiller - Not only is the GOOD shared example missing, but it seems to have nothing to do with the BAD code.

Copy link

aesyondu commented Apr 2, 2020

Hmm, so shared examples is just a replacement for copy paste right? I had a hard time parsing the original documentation.

For those familiar with jest, I believe it behaves similar to describe.each

Use describe.each if you keep duplicating the same test suites with different data. describe.each allows you to write the test suite once and pass data in.

Copy link

What about this ?

Isn't DRY a bad idea for tests? (in general)

Copy link

Yep, I agree that DAMP is often better than DRY in specs.

It's a trade off between dryness and readability. That SO question is excellent.

Testing is an art, not a science. So I think there is room for personal style here...

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

No branches or pull requests

9 participants