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

Review RSpec/BeforeAfterAll: Beware of using before/after(:all) rubocop warning #199

Open
vinzent opened this issue Feb 22, 2017 · 2 comments

Comments

@vinzent
Copy link
Contributor

vinzent commented Feb 22, 2017

new error with rubocop-rspec 1.12:

spec/acceptance/selinux_permissive_spec.rb:9:5: C: RSpec/BeforeAfterAll: Beware of using before/after(:all) as it may cause state to leak between tests. If you are using rspec-rails, and use_transactional_fixtures is enabled, then records created in before(:all) are not rolled back. 
    after :all do
    ^^^^^^^^^

comment on IRC:

the spec's not well-structured.. it has multiple "it" blocks (examples) that rely on the state set by a previous example, e.g. one example calls result.exit_code, the next runs a check, then after(:all) resets the system state.

probably best to move the shell() checks into the same it {} block that actually runs the test, or have the test re-run in each it {} block (rather unnecessary)

@oranenj
Copy link
Contributor

oranenj commented May 4, 2017

I suppose the specs could use a look-over, but the purpose of the before/after all blocks is to set up some state in the system for the module to act on, and then clean it up after the set of tests is done.

@Victorcorcos
Copy link

So what would be a valid replacement for the after(:all) statements?

I mean, before(:all) can be replaced by before_all from the Ruby Tests Profiling Toolbox, but there is not any after_all to replace the after(:all) of the test code suite.

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

3 participants