In Rspec, we can setup some global before/after behavior like this:
config.before(:each) {blah...}
I can say:
config.before(:each, :type => :model) {blah...}
To have this block run only with model tests
But this wouldn’t work:
config.before(:each, :type => [:model, :controller]) {blah...}
I have to repeat the same thing twice, one for model and one for controller. Is there any other way to do this? Thanks
Looking at RSpec filters: https://www.relishapp.com/rspec/rspec-core/docs/hooks/filters
They just match any arbitrary metadata, and rspec-rails adds the metadata :type => :model (or whatever) to each set of tests.
So, this config
would only match tests with this metadata (matching the same value):
Which basically means the answer to your question is NO.
Anyway, you could easily DIY it with something like this: