Created
August 1, 2014 15:58
-
-
Save myronmarston/a9d70e418d97e0d36c90 to your computer and use it in GitHub Desktop.
How to prevent before(:all) hooks in RSpec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PreventContextHooks | |
def before(*args) | |
disallow_context_or_all_hooks(args.first) | |
super | |
end | |
def after(*args) | |
disallow_context_or_all_hooks(args.first) | |
super | |
end | |
private | |
def disallow_context_or_all_hooks(scope) | |
return unless scope == :all || scope == :context | |
raise "Don't do that!" | |
end | |
end | |
RSpec.configure do |config| | |
config.extend PreventContextHooks | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment