Andi Schacke
2010-Dec-02 10:20 UTC
[rspec-users] Global before blocks - filtering by multiple types
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} Thanks Andi
David Chelimsky
2010-Dec-04 01:57 UTC
[rspec-users] Global before blocks - filtering by multiple types
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 end HTH, David