-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathspec_helper.rb
More file actions
130 lines (109 loc) · 3.5 KB
/
spec_helper.rb
File metadata and controls
130 lines (109 loc) · 3.5 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
126
127
128
129
130
ENV['RAILS_ENV'] ||= 'test'
puts "RUBY_ENGINE: #{RUBY_ENGINE}"
puts "RUBY_VERSION: #{RUBY_VERSION}\n\n"
##
# Code Climate
#
if ENV['GITHUB_ACTIONS'] && RUBY_ENGINE == 'ruby' && RUBY_VERSION.start_with?(ENV['COVERAGE_RUBY_VERSION'] || 'x')
require 'simplecov'
SimpleCov.start
end
##
# Load Rspec supporting files
#
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
##
# Detect Rails/Sinatra dummy application based on gemfile name substituted by Appraisal
#
if ENV['APPRAISAL_INITIALIZED'] || ENV['GITHUB_ACTIONS']
app_name = File.basename(ENV['BUNDLE_GEMFILE'], '.gemfile')
else
/.*?(?<app_name>rails.*?)\.gemfile/ =~ Dir["gemfiles/rails*.gemfile"].sort.last
end
##
# Load dummy application and Rspec
#
app_framework = %w{rails sinatra}.find { |f| app_name.to_s.include?(f) }
case app_framework
when 'rails'
# Load Rails
require 'logger'
require_relative "app/#{app_name}/config/environment"
APP_RAKEFILE = File.expand_path("../app/#{app_name}/Rakefile", __FILE__)
# Load Rspec
require 'rspec/rails'
# Configure
RSpec.configure do |config|
# Use fixture_paths (plural) for newer versions of RSpec
if config.respond_to?(:fixture_paths)
config.fixture_paths = [FixtureHelper::FIXTURE_PATH]
else
config.fixture_path = FixtureHelper::FIXTURE_PATH
end
end
when 'sinatra'
# Load Sinatra
require_relative "app/#{app_name}/app"
# Load Rspec
require 'rspec'
# Configure
RSpec.configure do |config|
config.filter_run_excluding :rails
config.include FixtureHelper
end
end
module FixturePathHelper
def fixture_path
# Call fixture_paths.first in Rails >= 7.1 to avoid deprecation warnings
respond_to?(:fixture_paths) ? fixture_paths.first : super
end
end
##
# Common Rspec configure
#
RSpec.configure do |config|
# Turn the deprecation warnings into errors, giving you the full backtrace
config.raise_errors_for_deprecations!
config.before(:suite) do
Config.module_eval do
# Extend Config module with ability to reset configuration to the default values
def self.reset
# Clear any existing Settings constant and its sources to prevent mock leakage
current_const_name = self.const_name
if Object.const_defined?(current_const_name)
settings_instance = Object.const_get(current_const_name)
# Clear the config sources to prevent mock doubles from leaking
if settings_instance.respond_to?(:instance_variable_set)
settings_instance.instance_variable_set(:@config_sources, [])
end
Object.send(:remove_const, current_const_name)
end
# Reset configuration to defaults
self.const_name = 'Settings'
self.use_env = false
self.knockout_prefix = nil
self.overwrite_arrays = true
self.schema = nil
self.validation_contract = nil
self.fail_on_missing = false
self.use_rails_credentials = false
self.file_name = 'settings'
self.dir_name = 'settings'
self.extra_sources = []
instance_variable_set(:@_ran_once, false)
end
end
end
config.include FixturePathHelper
end
##
# Print some debug info
#
puts
puts "Gemfile: #{ENV['BUNDLE_GEMFILE']}"
puts 'Version:'
Gem.loaded_specs.each { |name, spec|
puts "\t#{name}-#{spec.version}" if %w{rails activerecord-jdbcsqlite3-adapter sqlite3 rspec-rails sinatra}.include?(name)
}
puts "\tpsych-#{Psych::VERSION}"
puts