Last Updated: February 25, 2016
·
1.168K
· rorcraft

RSpec database truncate before all block

RSpec.configure do |config|

    config.before(:each) do
      if example.metadata[:database_cleaner] != :all
        DatabaseCleaner.start
      end
    end

    config.after(:each) do
      if example.metadata[:database_cleaner] != :all
        DatabaseCleaner.clean
      end
    end

    config.before(:all, database_cleaner: :all) do
      DatabaseCleaner.clean
    end

    config.after(:all, database_cleaner: :all) do
      DatabaseCleaner.clean
    end

end
describe '.my_method', :database_cleaner => :all do
    before(:all) do
        # ... setup 
    end

    # reuse created data
    it "should be this"
    it "should be that"

end