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

Add ExampleLength cop #85

Merged
merged 1 commit into from May 16, 2016
Merged

Conversation

andyw8
Copy link
Collaborator

@andyw8 andyw8 commented May 2, 2016

This was suggested by @agrimm in issue #40

A long example is a form of the Obscure Test smell:
http://xunitpatterns.com/Obscure%20Test.html

I've chosen a default maximum of 5 lines on the basis that a typical
example would contain 3 lines of setup, one line of execution and one
line of assertion. However, this is quite dependent on the style used in
the codebase. Suites which rely more on let and before blocks would
likely have shorter example blocks.

Somewhat ironically, I had to set the configuration for rubocop-rspec
itself to quite a high value (12 lines).

@andyw8 andyw8 mentioned this pull request May 2, 2016
cop_config['Max']
end

def code_length(node)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyw8
Copy link
Collaborator Author

andyw8 commented May 8, 2016

TODO:

  • Add changelog entry

@andyw8 andyw8 force-pushed the add-long-example-cop branch 5 times, most recently from 2c269f2 to ddc813c Compare May 15, 2016 18:32
@@ -2,6 +2,7 @@

## master (unreleased)

* Add `RSpec::LongExample` cop. ([@andyw8][])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rspec::ExampleLength

@andyw8
Copy link
Collaborator Author

andyw8 commented May 15, 2016

@nijikon updated based on your suggestions.

@andyw8 andyw8 changed the title Add LongExample cop Add ExampleLength cop May 15, 2016
@nijikon
Copy link
Collaborator

nijikon commented May 15, 2016

@andyw8 please rebase on top of master

This was suggested by @agrimm in issue rubocop#40

A long example is a form of the Obscure Test smell:
http://xunitpatterns.com/Obscure%20Test.html

I've chosen a default maximum of 5 lines on the basis that a typical
example would contain 3 lines of setup, one line of execution and one
line of assertion. However, this is quite dependent on the style used in
the codebase. Suites which rely more on `let` and `before` blocks would
likely have shorter example blocks.

Somewhat ironically, I had to set the configuration for rubocop-rspec
itself to quite a high value (12 lines).
@andyw8
Copy link
Collaborator Author

andyw8 commented May 16, 2016

@nijikon done

@nijikon nijikon merged commit 7e090b8 into rubocop:master May 16, 2016
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

Successfully merging this pull request may close these issues.

None yet

3 participants