Questions tagged [database-cleaner]

Database Cleaner is a set of strategies for cleaning your database in Ruby, primarily for testing purposes.

Database Cleaner is a set of strategies for cleaning your database in Ruby.

The original use case was to ensure a clean state during tests. Each strategy is a small amount of code but is code that is usually needed in any ruby app that is testing with a database.

ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.

https://github.com/DatabaseCleaner/database_cleaner

145 questions
40
votes
1 answer

Is DatabaseCleaner still necessary with Rails system specs?

From all that I've read about Rails 5.1 new system specs my understanding was that Rails now handles database transactions internally. From Rspec's blog: "[previously] your tests and your code under test cannot share a database transaction, and so…
Andy Harvey
  • 12,333
  • 17
  • 93
  • 185
22
votes
3 answers

DatabaseCleaner + RSpec : what is the correct configuration?

I included database_cleaner gem in my rails app. Followed the example given on the git repo and included the following code in spec_helper : Approach 1 config.before(:suite) do DatabaseCleaner.strategy = :transaction …
Kirti Thorat
  • 52,578
  • 9
  • 101
  • 108
14
votes
1 answer

Running integration/acceptance tests on the frontend. Need an API for the frontend to tell Rails which database state to set up for each test

My frontend is an EmberJS-based app. It's totally async in nature, so testing it with Capybara is pain and misery. On the other hand, Ember provides a fantastic test suite out of the box which makes acceptance testing fun and effective. Normally,…
10
votes
4 answers

Cleaning database after tests in node.js

How I can clean database after each it? In rails I use https://github.com/bmabey/database_cleaner, but I did't find something similar for node.js node.js (v0.10.26), PostgreSQL (9.3.3), mocha, restify and knex.
frootloops
  • 103
  • 1
  • 4
10
votes
2 answers

Database Cleaner issue with Capybara webkit

I am using Cucumber to write my integration tests and Database Cleaner to keep my db clean. Everything perfectly works as my tests don't require Javascript. I can make these last tests pass using Capybara webkit, but then my db is not cleaned at…
9
votes
3 answers

how to clean database before running the each spec file?

I want to clear my test database before running the each spec files. I am already using rspec with factory girl. Thanks, Hare
Hare Ram
  • 743
  • 2
  • 7
  • 19
9
votes
5 answers

Rspec - How to clean the database after each test

I have a feature spec with Capybara for a login page, and I am using FactoryGirl + DatabaseCleaner require 'rails_helper' feature 'Admin signs in' do background do FactoryGirl.create(:user) end scenario 'with valid credentials' do …
Carlo
  • 1,184
  • 4
  • 15
  • 31
9
votes
4 answers

How can I clean my database between erroneous rspec specs?

I have added the database_cleaner gem to my rails application in order to clean my database between specs. Here's my current configuration for database_cleaner, located in spec/spec_helper.rb: config.before(:suite) do DatabaseCleaner.strategy…
Starkers
  • 10,273
  • 21
  • 95
  • 158
8
votes
5 answers

Database Cleaner not working in minitest rails

My Minitest controller tests are working fine if I run them alone using rake minitest:controllers but when I run rake minitest:all then I get validation failed error. It is because email is already used in model tests. I used DatabaseCleaner to…
Anil Maurya
  • 2,298
  • 1
  • 22
  • 28
8
votes
3 answers

Upgrading capybara from 1.0.1 to 1.1.4 makes database_cleaner break my specs

I have an old Rails application upgraded to version 3.2.11 that has a lot of request specifications written using capybara version 1.0.1 and running using the selenium driver. The database are cleaned after each test using database_cleaner using the…
HakonB
  • 6,977
  • 1
  • 26
  • 27
7
votes
1 answer

custom transaction doesn't work with database_cleaner in rspec

In our Rails 4.0 application using MySql we use rspec together with the database_cleaner gem configured with strategy :transaction to cleanup our database for every test case. If we have custom transactions, which should be rollbacked, it doesn't…
crimi
  • 746
  • 1
  • 7
  • 8
6
votes
1 answer

PG::ConnectionBad: connection is closed after upgrading rails from 4.2 to 5.2

I have upgraded my rails version of a project from 4.2 to 5.2.1 some of my tests are failed because of pg connection closed error on the full trace is is as following. Failure/Error: DatabaseCleaner[:active_record].clean_with(:truncation) …
Asnad Atta
  • 3,855
  • 1
  • 32
  • 49
6
votes
1 answer

DatabaseCleaner raising NoMethodError: undefined method `rollback' for nil:NilClass

I have a rails app using rspec and including DatabseCleaner to ensure the test database is clean between each test. DatabaseCleaner is configured in our spec/rails_helper.rb with config.before(:suite) do DatabaseCleaner.strategy =…
6
votes
1 answer

Foreign Key constraint issues using sequel and database cleaner

I am running into issues using database cleaner with sequel and sqlite foreign key constraints. Specifically, I am using the :truncation strategy with Capybara integration tests. For the given sample schema: CREATE TABLE users(id INTEGER PRIMARY…
Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90
6
votes
1 answer

DatabaseCleaner.clean_with(:truncate) does not reset auto incremented id

I am currently using DatabaseCleaner in my Rails project with PostgreSQL running, and set it up as below. RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation, { pre_count: true, reset_ids: true }) …
1
2 3
9 10