not type for hooks

8 views
Skip to first unread message

Jonathan Greenberg

unread,
Mar 24, 2014, 10:53:56 AM3/24/14
to rs...@googlegroups.com
I am wondering if there is an existing syntax for not running a hook in specs of a certain type. For example:

config.before(not_type: :feature) do
  this_would_blow_up_a_feature_spec
end

I have not found anything like this in the documentation but I could easily be overlooking.

Thanks!

Myron Marston

unread,
Mar 24, 2014, 11:15:11 AM3/24/14
to rs...@googlegroups.com
You can do this:

RSpec.configure do |config|
  config.before(:each) do |ex|
    unless ex.metadata[:type] == :feature
       this_would_blow_up_a_feature_spec
    end
  end
end

That assumes you are on 2.99 or 3.0.  If you're on an earlier version, remove the block `ex` args and use `example.metadata` instead of `ex.metadata`.

HTH,
Myron
Reply all
Reply to author
Forward
0 new messages