Permalink
Browse files

Better database cleaning during tests with Database Cleaner

  • Loading branch information...
1 parent 8f04b1d commit f92eaf03521637e1ab00a94648db2209376de2c7 @jcasimir jcasimir committed Jan 11, 2012
Showing with 22 additions and 18 deletions.
  1. +3 −1 Gemfile
  2. +6 −2 Gemfile.lock
  3. +13 −15 spec/spec_helper.rb
View
4 Gemfile
@@ -17,5 +17,7 @@ group :development, :test do
gem 'fabrication'
gem 'guard'
gem 'guard-rspec'
- gem 'rb-fsevent'
+ #gem 'rb-fsevent'
+ gem 'database_cleaner'
+ gem 'launchy'
end
View
8 Gemfile.lock
@@ -29,6 +29,7 @@ GEM
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
+ addressable (2.2.6)
arel (2.2.1)
builder (3.0.0)
capybara (1.1.2)
@@ -47,6 +48,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
+ database_cleaner (0.7.0)
diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.13)
@@ -66,6 +68,8 @@ GEM
railties (~> 3.0)
thor (~> 0.14)
json (1.6.4)
+ launchy (2.0.5)
+ addressable (~> 2.2.6)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -99,7 +103,6 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
- rb-fsevent (0.4.3.1)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
@@ -150,13 +153,14 @@ PLATFORMS
DEPENDENCIES
capybara
coffee-rails (~> 3.1.1)
+ database_cleaner
fabrication
faker
guard
guard-rspec
jquery-rails
+ launchy
rails (= 3.1.3)
- rb-fsevent
rspec-rails
sass-rails (~> 3.1.5)
sqlite3
View
28 spec/spec_helper.rb
@@ -4,26 +4,24 @@
require 'rspec/rails'
require 'capybara/rails'
require 'capybara/rspec'
+require 'database_cleaner'
-# Requires supporting ruby files with custom matchers and macros, etc,
-# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
- # == Mock Framework
- #
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
- #
- # config.mock_with :mocha
- # config.mock_with :flexmock
- # config.mock_with :rr
config.mock_with :rspec
+ config.use_transactional_fixtures = false
- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
+ config.before(:suite) do
+ DatabaseCleaner.strategy = :transaction
+ DatabaseCleaner.clean_with(:truncation)
+ end
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
- # examples within a transaction, remove the following line or assign false
- # instead of true.
- config.use_transactional_fixtures = true
+ config.before(:each) do
+ DatabaseCleaner.start
+ end
+
+ config.after(:each) do
+ DatabaseCleaner.clean
+ end
end

0 comments on commit f92eaf0

Please sign in to comment.