This repository has been archived by the owner on Mar 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
rails_helper.rb
92 lines (78 loc) · 3.07 KB
/
rails_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true
ENV['RAILS_ENV'] = 'test'
require 'spec_helper'
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'rspec/json_expectations'
require 'database_cleaner'
require 'devise'
require 'support/helper_functions'
require 'support/omni_auth_helper'
require 'support/capybara'
require 'controllers/shared_examples'
require 'support/request_helpers'
require 'webmock/rspec'
require 'paper_trail/frameworks/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
Capybara.javascript_driver = :poltergeist
ActiveRecord::Migration.maintain_test_schema!
VCR.configure do |config|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
config.hook_into :webmock
config.ignore_localhost = true
config.default_cassette_options = {
match_requests_on: %i[path host method],
record: :once
}
%w[merchant_id public_key private_key].each do |env|
config.filter_sensitive_data("<#{env}>") { Settings.braintree.send(env) }
end
config.filter_sensitive_data('<shareprogress_api_key>') { ENV['SHARE_PROGRESS_API_KEY'] }
config.filter_sensitive_data('<gocardless_token>') { Settings.gocardless.token }
config.filter_sensitive_data('<oxr_app_id>') { Settings.oxr_app_id }
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.include Devise::Test::ControllerHelpers, type: :controller
config.include HelperFunctions
config.include OmniAuthHelper
config.extend ControllerMacros, type: :controller
config.include Warden::Test::Helpers, type: :request
config.include Requests::RequestHelpers, type: :request
config.infer_spec_type_from_file_location!
# During testing, the app-under-test that the browser driver connects to
# uses a different database connection to the database connection used by
# the spec. The app's database connection would not be able to access
# uncommitted transaction data setup over the spec's database connection.
config.use_transactional_fixtures = false
config.before(:suite) do
Warden.test_mode!
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.cleaning do
FactoryGirl.lint
end
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
Settings.reload!
end
config.before(:each, type: :feature) do
# :rack_test driver's Rack app under test shares database connection
# with the specs, so continue to use transaction strategy for speed.
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
unless driver_shares_db_connection_with_specs
# Driver is probably for an external browser with an app
# under test that does *not* share a database connection with the
# specs, so use truncation strategy.
DatabaseCleaner.strategy = :truncation
end
end
config.append_after(:each) do
DatabaseCleaner.clean
end
end