[rspec-users] Global before blocks - filtering by multiple types

David Chelimsky dchelimsky at gmail.com
Fri Dec 3 20:57:54 EST 2010

On Dec 2, 2010, at 4:20 AM, Andi Schacke wrote:

> Hi
> in the config block of rspec I have a before block to reset my
> database before each spec:
> config.before(:each) {DatabaseCleaner.clean}
> I know I can apply this before to a specific type, e.g.
> config.before(:each, :type => :model) {DatabaseCleaner.clean}
> but what I want to achieve is that the database is cleaned for all
> specs except acceptance specs. Is there a way to define this, e.g.
> something like:
> config.before(:each, :except => :acceptance) {DatabaseCleaner.clean}
> or maybe
> config.before(:each, :type => [:model, :view, :controller])
> {DatabaseCleaner.clean}

Not exactly, but there is another way:

config.before(:each) do
  DatabaseCleaner.clean unless example.metadata[:type] == :acceptance


More information about the rspec-users mailing list