|
1 | 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' |
2 | | -require 'spec_helper' |
| 2 | +require 'devise' |
| 3 | +require 'warden' |
| 4 | + |
3 | 5 | ENV['RAILS_ENV'] ||= 'test' |
4 | 6 | require_relative '../config/environment' |
5 | 7 | # Prevent database truncation if the environment is production |
|
34 | 36 | rescue ActiveRecord::PendingMigrationError => e |
35 | 37 | abort e.to_s.strip |
36 | 38 | end |
| 39 | + |
37 | 40 | RSpec.configure do |config| |
38 | 41 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures |
39 | 42 | config.fixture_paths = [ |
|
69 | 72 | config.filter_rails_from_backtrace! |
70 | 73 | # arbitrary gems may also be filtered via: |
71 | 74 | # config.filter_gems_from_backtrace("gem name") |
| 75 | + |
| 76 | + # Include FactoryBot methods |
| 77 | + config.include FactoryBot::Syntax::Methods |
| 78 | + |
| 79 | + # Include Devise test helpers |
| 80 | + config.include Devise::Test::IntegrationHelpers, type: :request |
| 81 | + config.include Devise::Test::IntegrationHelpers, type: :controller |
| 82 | + config.include Warden::Test::Helpers |
| 83 | + |
| 84 | + # Database Cleaner configuration |
| 85 | + config.before(:suite) do |
| 86 | + DatabaseCleaner.clean_with(:truncation) |
| 87 | + end |
| 88 | + |
| 89 | + config.before(:each) do |
| 90 | + DatabaseCleaner.strategy = :transaction |
| 91 | + end |
| 92 | + |
| 93 | + config.before(:each, js: true) do |
| 94 | + DatabaseCleaner.strategy = :truncation |
| 95 | + end |
| 96 | + |
| 97 | + config.before(:each) do |
| 98 | + DatabaseCleaner.start |
| 99 | + end |
| 100 | + |
| 101 | + config.after(:each) do |
| 102 | + DatabaseCleaner.clean |
| 103 | + end |
| 104 | + |
| 105 | + config.after(:each) do |
| 106 | + Warden.test_reset! |
| 107 | + end |
| 108 | +end |
| 109 | + |
| 110 | +# Shoulda Matchers configuration |
| 111 | +Shoulda::Matchers.configure do |config| |
| 112 | + config.integrate do |with| |
| 113 | + with.test_framework :rspec |
| 114 | + with.library :rails |
| 115 | + end |
72 | 116 | end |
0 commit comments