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 Declare Constants guideline #101

Merged
merged 1 commit into from Jul 11, 2019

Conversation

@pirj
Copy link
Member

commented Jul 11, 2019

Constants defined in a block are defined in a global namespace, and are not cleared up between examples.

If several examples may define a DummyClass, instead of being a blank slate class as it will be in the first example, subsequent examples will be reopening it and modifying its behaviour in unpredictable ways.
Even worse when a class that exists in the codebase is reopened.

Anonymous classes are fine since they don't result in global namespace name clashes.

Related RSpec/LeakyConstantDeclaration cop (follow the link for a lot of reasoning behind it).

More accessible representation of the added guideline https://github.com/rubocop-hq/rspec-style-guide/blob/add-leaky-constant-guideline/README.adoc#declare-constants

Add Declare Constants guideline
Constants defined in a block are defined in a global namespace, and are
not cleared up between examples.

If several examples may define a `DummyClass`, instead of being a blank
slate class as it will be in the first example, subsequent examples will
be reopening it and modifying its behaviour in unpredictable ways.  Even
worse when a class that exists in the codebase is reopened.

Anonymous classes are fine, since they don't result in global namespace
name clashes.

@pirj pirj self-assigned this Jul 11, 2019

@pirj pirj requested review from dgollahon, Darhazer and bquorning Jul 11, 2019

@pirj pirj merged commit b12fe28 into master Jul 11, 2019

1 check passed

ci/circleci: docs-build Your tests passed on CircleCI!
Details

@pirj pirj deleted the add-leaky-constant-guideline branch Jul 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.