Clearing RSpec hooks inside a spec
There aren't a lot of use cases where you want to clear the global RSpec before
/after
hooks, but I needed it in a specific file from my suite that I didn't want to just copy the spec_helper.rb
to do that.
RSpec.configuration.hooks.send(:instance_variable_get, :@data)[:before][:example] = RSpec::Core::Hooks::HookCollection.new
RSpec.configuration.hooks.send(:instance_variable_get, :@data)[:after][:example] = RSpec::Core::Hooks::HookCollection.new
That's more a workaround than a real solution. Just to remember: that must be done before the describe
block.
Written by Daniel Garajau
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#