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

140 questions
30
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
  • 11,339
  • 14
  • 76
  • 166
21
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
  • 50,170
  • 10
  • 97
  • 103
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
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
  • 9,083
  • 14
  • 82
  • 143
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,200
  • 1
  • 20
  • 27
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,537
  • 1
  • 23
  • 27
7
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,105
  • 4
  • 14
  • 28
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
  • 726
  • 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,429
  • 27
  • 39
6
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
  • 573
  • 1
  • 5
  • 19
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
  • 25,904
  • 10
  • 55
  • 84
6
votes
5 answers

database_cleaner is wiping my development database

I have database-cleaner configured for my rails 4 application, Each time I run the test, I discovered that my database gets wiped out in both the test and development environment. My configurations are in rails_helper as follow: ENV["RAILS_ENV"] ||=…
x6iae
  • 3,675
  • 1
  • 23
  • 48
6
votes
2 answers

Rspec extremely slow

My rspec tests seem to run extremely slow even with guard & spork. Finished in 5.36 seconds 13 examples, 2 failures I understand that there are several things I can do to optimize my tests & reduce interaction with the database, but I strongly…
1
2 3
9 10