-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathspec_helper.rb
More file actions
125 lines (103 loc) · 3.83 KB
/
Copy pathspec_helper.rb
File metadata and controls
125 lines (103 loc) · 3.83 KB
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
# frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'
require 'database_cleaner'
require 'etc'
require 'fileutils'
require 'capybara/poltergeist'
require 'simplecov'
require 'tailoring'
# require 'rspec_remote_formatter'
SimpleCov.start 'rails' do
add_filter '/bin/'
add_filter '/db/'
add_filter '/spec/'
end
Rack::Attack.enabled = false
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Require everything in lib too.
# Dir[Rails.root.join('lib/**/*.rb')].each { |f| require f }
# Use :selenium this if you want to see what's going on and don't feel like screenshotting
# Otherwise :poltergeist with PhantomJS is somewhat faster and doesn't pop up in your face.
#
# Recommendation for Selenium: run tests under Xvfb:
# In console 1: Xvfb :99
# In console 2: env DISPLAY=:99 rvmsudo rake spec
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, timeout: 60, js_errors: false)
end
Capybara.default_driver = :poltergeist
Capybara.server = :puma, { Silent: true }
Capybara.server_port = FreePorts.take_next
Capybara.default_max_wait_time = 60 # Comet messages may take longer to appear than the default 2 sec
Capybara.ignore_hidden_elements = false
if Capybara.default_driver == :selenium
Capybara.current_session.driver.browser.manage.window.resize_to 1250, 900
end
def get_m3_home
`mvn --version | grep "Maven home" | sed 's/Maven home: //'`.chomp
end
if ENV['M3_HOME'].blank?
maven_home = get_m3_home
warn "$M3_HOME is not set, trying with #{maven_home} - however, maven tests might be failing"
ENV['M3_HOME'] = maven_home
end
RustLangsDownloaderTask.new.run
def without_db_notices
ActiveRecord::Base.connection.execute("SET client_min_messages = 'warning'")
yield
ActiveRecord::Base.connection.execute("SET client_min_messages = 'notice'")
end
def host_ip
@addr ||= ENV['HOST'] ||= if ENV['CI']
`ip addr|awk '/eth0/ && /inet/ {gsub(/\\/[0-9][0-9]/,""); print $2}'`.chomp
else
'127.0.0.1'
end
end
# This makes it visible to others
Capybara.server_host = if ENV['MULTI_HOST_SETUP']
'0.0.0.0'
else
host_ip
end
RSpec.configure do |config|
config.mock_with :rspec
config.raise_errors_for_deprecations!
config.use_transactional_fixtures = false
config.include FactoryBot::Syntax::Methods
config.include Capybara::DSL
config.before(:each) do |context|
allow(Tailoring).to receive_messages(get: Tailoring.new)
SiteSetting.use_distribution_defaults!
SiteSetting.all_settings['administrative_email'] = 'test@example.com'
if context.metadata[:integration] || context.metadata[:feature]
# integration tests can't use transaction since the webserver must see the changes
DatabaseCleaner.strategy = :truncation
# SiteSetting.all_settings['baseurl_for_remote_sandboxes'] = "http://#{host_ip}:#{Capybara.server_port}"
SiteSetting.all_settings['baseurl_for_remote_sandboxes'] = "http://#{host_ip}:3000/"
SiteSetting.all_settings['remote_sandboxes'] = ["http://#{host_ip}:3232/"]
SiteSetting.all_settings['emails']['email_code_reviews_by_default'] = false
else
DatabaseCleaner.strategy = :transaction
end
DatabaseCleaner.start
end
config.after(:each) do |_context|
without_db_notices do
DatabaseCleaner.clean
end
end
# Override with rspec --tag ~integration --tag gdocs spec
config.filter_run_excluding gdocs: true
end
# Ensure the DB is clean
DatabaseCleaner.strategy = :truncation # May cause problems with multiple processes
DatabaseCleaner.start
without_db_notices do
DatabaseCleaner.clean
end