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

What's a good value for RSpec example length? #248

Open
mokagio opened this issue May 3, 2021 · 1 comment
Open

What's a good value for RSpec example length? #248

mokagio opened this issue May 3, 2021 · 1 comment

Comments

@mokagio
Copy link
Contributor

mokagio commented May 3, 2021

When working on #242, I added some tests and RuboCop warned me they should have been 5 lines or less.

RSpec/ExampleLength: Example has too many lines [7/5].

I addressed the violation with a cheap trick.

I'm all in for having short methods actually, I do really like the Sandi Metz rules. But, in the context of that commit, I feel like I didn't make the test more readable.

I can see two options:

  • Relax the rule to acknowledge the current state of this codebase, where there's a lot of setup and mocking required for testing
  • Stick with the rule, and do our best to work within it in a way that makes the codebase better.
mokagio added a commit that referenced this issue May 3, 2021
This was to comply with the RuboCop rule on the example length, which
wants examples at 5 lines or less.

To be honest, I feel like I'm cheating a bit here and I feel maybe the
test is less readable as a result.

Opened #248 to track this discussion.
@mokagio
Copy link
Contributor Author

mokagio commented May 3, 2021

I feel like I didn't make the test more readable.

As an aside, something else I could have done was extracting that setup logic in a method so that it would have been a one liner all in the example and I would have satisfied the RuboCop requirement 🤔

mokagio added a commit that referenced this issue May 6, 2021
See also #248.

I actually had already addressed this in
b63a2a3, but then reverted it to track
the RuboCop violation and didn't realize the revert made it upstream...

This is a better solution anyways, I think.
mokagio added a commit that referenced this issue May 12, 2021
See also #248.

I actually had already addressed this in
b63a2a3, but then reverted it to track
the RuboCop violation and didn't realize the revert made it upstream...

This is a better solution anyways, I think.
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

1 participant