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
Written by Rex Chung
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rspec
Authors
Related Tags
#rspec
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#