Skip to content

Instantly share code, notes, and snippets.

@yokolet
Created September 21, 2017 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yokolet/506e4d7307939f8e08f06337e539bec0 to your computer and use it in GitHub Desktop.
Save yokolet/506e4d7307939f8e08f06337e539bec0 to your computer and use it in GitHub Desktop.
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 46ba8e0..3b99862 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -7,6 +7,8 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
+require 'database_cleaner'
+
# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
@@ -26,9 +28,17 @@ require 'rspec/rails'
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
+# Configure shoulda matchers
+Shoulda::Matchers.configure do |config|
+ config.integrate do |with|
+ with.test_framework :rspec
+ with.library :rails
+ end
+end
+
RSpec.configure do |config|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
+ #config.fixture_path = "#{::Rails.root}/spec/fixtures"
# 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
@@ -54,4 +64,19 @@ RSpec.configure do |config|
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
+
+ # Configure FactoryGirl
+ config.include FactoryGirl::Syntax::Methods
+
+ # Configure database cleaner
+ config.before(:suite) do
+ DatabaseCleaner.clean_with(:truncation)
+ DatabaseCleaner.strategy = :transaction
+ end
+
+ config.around(:each) do |example|
+ DatabaseCleaner.cleaning do
+ example.run
+ end
+ end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment