Skip to content

Commit 9f6f786

Browse files
committedOct 13, 2015
Add database_cleaner and testing configurations
1 parent 5b54667 commit 9f6f786

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed
 

‎.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
--color
22
--require spec_helper
3+
--format documentation

‎Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,6 @@ group :development, :test do
5050
gem 'factory_girl_rails'
5151
# Use faker for data population
5252
gem 'faker'
53+
# Use database_cleaner in place of transactional fixtures
54+
gem 'database_cleaner'
5355
end

‎Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ GEM
6161
coffee-script-source
6262
execjs
6363
coffee-script-source (1.9.1.1)
64+
database_cleaner (1.4.1)
6465
debug_inspector (0.0.2)
6566
diff-lcs (1.2.5)
6667
em-websocket (0.5.1)
@@ -234,6 +235,7 @@ DEPENDENCIES
234235
capybara
235236
coffee-rails (~> 4.1.0)
236237
font-awesome-rails (~> 4.4.0.0)
238+
database_cleaner
237239
factory_girl_rails
238240
faker
239241
guard-livereload

‎config/application.rb

+9
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,14 @@ class Application < Rails::Application
3131

3232
# Do not swallow errors in after_commit/after_rollback callbacks.
3333
config.active_record.raise_in_transactional_callbacks = true
34+
config.generators do |g|
35+
g.test_framework :rspec, fixtures: true,
36+
view_specs: false,
37+
helpers_specs: false,
38+
routing_specs: false,
39+
controller_specs: true,
40+
request_specs: false
41+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
42+
end
3443
end
3544
end

‎spec/rails_helper.rb

+27-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
4040
config.fixture_path = "#{::Rails.root}/spec/fixtures"
4141

42-
# If you're not using ActiveRecord, or you'd prefer not to run each of your
43-
# examples within a transaction, remove the following line or assign false
44-
# instead of true.
45-
config.use_transactional_fixtures = true
46-
4742
# RSpec Rails can automatically mix in different behaviours to your tests
4843
# based on their file location, for example enabling you to call `get` and
4944
# `post` in specs under `spec/controllers`.
@@ -58,4 +53,31 @@
5853
# The different available types are documented in the features, such as in
5954
# https://relishapp.com/rspec/rspec-rails/docs
6055
config.infer_spec_type_from_file_location!
56+
57+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
58+
# examples within a transaction, remove the following line or assign false
59+
# instead of true.
60+
config.use_transactional_fixtures = false
61+
62+
# Use database_cleaner in place of transactional fixtures
63+
config.before(:suite) do
64+
DatabaseCleaner.clean_with(:truncation)
65+
end
66+
67+
config.before(:each) do
68+
DatabaseCleaner.strategy = :transaction
69+
end
70+
71+
config.before(:each, :js => true) do
72+
DatabaseCleaner.strategy = :truncation
73+
end
74+
75+
config.before(:each) do
76+
DatabaseCleaner.start
77+
end
78+
79+
config.after(:each) do
80+
DatabaseCleaner.clean
81+
end
82+
6183
end

0 commit comments

Comments
 (0)
Please sign in to comment.