-
Notifications
You must be signed in to change notification settings - Fork 115
/
rails_helper.rb
163 lines (138 loc) · 5.19 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# This file is copied to spec/ when you run 'rails generate rspec:install'
if ENV['COVERAGE']
require './spec/simplecov_helper'
SimplecovHelper.start
end
ENV['RAILS_ENV'] = 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_unit/railtie'
require 'rspec/rails'
require 'spec_helper'
require 'email_spec'
require 'email_spec/rspec'
require 'factory_bot'
require 'view_component/test_helpers'
require 'capybara/rspec'
require 'capybara/webmock'
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.maintain_test_schema!
# Require all .rb files in spec/support _except_ things that are actually specs.
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each do |f|
require f unless f.end_with?('_spec.rb')
end
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.include ActiveSupport::Testing::TimeHelpers
config.include EmailSpec::Helpers
config.include EmailSpec::Matchers
config.include AbstractController::Translation
config.include MailerHelper
config.include Features::SessionHelper, type: :feature
config.include Features::StripTagsHelper, type: :feature
config.include ViewComponent::TestHelpers, type: :component
config.include Capybara::RSpecMatchers, type: :component
config.include AgreementsHelper
config.include AnalyticsHelper
config.include IrsAttemptsApiTrackingHelper
config.include AwsKmsClientHelper
config.include KeyRotationHelper
config.include OtpHelper
config.include XmlHelper
config.before(:suite) do
Rails.application.load_seed
class Analytics
prepend FakeAnalytics::PiiAlerter
prepend FakeAnalytics::UndocumentedParamsChecker
end
begin
REDIS_POOL.with { |client| client.info }
rescue RuntimeError => error
# rubocop:disable Rails/Output
puts error
puts 'It appears Redis is not running, but it is required for (some) specs to run'
exit 1
# rubocop:enable Rails/Output
end
end
if !ENV['CI'] && !ENV['SKIP_BUILD']
config.before(js: true) do
# rubocop:disable Style/GlobalVars
next if defined?($ran_asset_build)
$ran_asset_build = true
# rubocop:enable Style/GlobalVars
# rubocop:disable Rails/Output
print ' Bundling JavaScript and stylesheets... '
system 'WEBPACK_PORT= yarn concurrently "yarn:build:*" > /dev/null 2>&1'
puts '✨ Done!'
# rubocop:enable Rails/Output
end
end
config.before(:each) do
I18n.locale = :en
end
config.before(:each, js: true) do
server = Capybara.current_session.server
server_domain = "#{server.host}:#{server.port}"
allow(IdentityConfig.store).to receive(:domain_name).and_return(server_domain)
default_url_options = ApplicationController.default_url_options.merge(host: server_domain)
self.default_url_options = default_url_options
allow(Rails.application.routes).to receive(:default_url_options).and_return(default_url_options)
end
config.before(:each, type: :controller) do
@request.host = IdentityConfig.store.domain_name
end
config.before(:each) do
allow(ValidateEmail).to receive(:mx_valid?).and_return(true)
end
config.before(:each) do
Telephony::Test::Message.clear_messages
Telephony::Test::Call.clear_calls
PushNotification::LocalEventQueue.clear!
REDIS_THROTTLE_POOL.with { |client| client.flushdb }
end
config.before(:each) do
DocAuth::Mock::DocAuthMockClient.reset!
descendants = ActiveJob::Base.descendants + [ActiveJob::Base]
ActiveJob::Base.queue_adapter = :inline
descendants.each(&:disable_test_adapter)
end
config.before(:each) do
Rails.cache.clear
end
config.around(:each, type: :feature) do |example|
Bullet.enable = true
Capybara::Webmock.start
example.run
Capybara::Webmock.stop
Bullet.enable = false
end
config.around(:each, freeze_time: true) do |example|
freeze_time { example.run }
end
config.after(:each, type: :feature, js: true) do |spec|
next unless page.driver.browser.respond_to?(:manage)
# Always get the logs, even if logs are allowed for the spec, since otherwise unexpected
# messages bleed over between specs.
javascript_errors = page.driver.browser.logs.get(:browser).map(&:message)
next if spec.metadata[:allow_browser_log]
# Temporarily allow for document-capture bundle, since it uses React error boundaries to poll.
javascript_errors.reject! { |e| e.include? 'submission-complete' }
# Consider any browser console logging as a failure.
raise BrowserConsoleLogError.new(javascript_errors) if javascript_errors.present?
end
config.around(:each, allow_net_connect_on_start: true) do |example|
# Avoid "Too many open files - socket(2)" error on some local machines
WebMock.allow_net_connect!(net_http_connect_on_start: true)
example.run
WebMock.disable_net_connect!(
allow: [
/localhost/,
/127\.0\.0\.1/,
/codeclimate.com/, # For uploading coverage reports
/chromedriver\.storage\.googleapis\.com/, # For fetching a chromedriver binary
],
)
end
end