brooklynDev/airborne

Clear database before specific test

Closed this issue · 1 comments

I want to test one method when database is empty, so i want to clear the database before my test (only ONE test case).
I know that DatabaseCleaner can clear database each test case. But how about only ONE?

If I understand correctly, its just an RSpec, so, you can call the DatabaseCleaner in any of your examples

it 'does something with clean database' do
  DatabaseCleaner.clean
  # rest of your example here
end

or put it into :before block for one or more examples . If you want, you can isolate it with context:

describe 'Something' do
  context 'with clean database' do
    before { DatabaseCleaner.clean }
    it "does something with clean database" do
      # your example here
    end
  end
end