Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.