Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created August 1, 2014 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/a9d70e418d97e0d36c90 to your computer and use it in GitHub Desktop.
Save myronmarston/a9d70e418d97e0d36c90 to your computer and use it in GitHub Desktop.
How to prevent before(:all) hooks in RSpec
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