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

Open
andreareginato opened this issue Oct 3, 2012 · 8 comments
Open

Shared Examples #13

andreareginato opened this issue Oct 3, 2012 · 8 comments
Labels

Comments

@andreareginato
Copy link
Collaborator

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

@dgm
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.

@cupakromer
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 https://www.relishapp.com/rspec/rspec-core/v/2-11/docs/example-groups/shared-examples for examples of this.

@gavingmiller
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.

@iRet
Copy link

iRet commented Sep 18, 2014

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

@georgeu2000
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.

@aesyondu
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.

@juanmanuelramallo
Copy link

What about this https://stackoverflow.com/questions/6453235/what-does-damp-not-dry-mean-when-talking-about-unit-tests ?

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

@george-distiller
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
Labels
Projects
None yet
Development

No branches or pull requests

9 participants