-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
spec_helper.rb
78 lines (60 loc) 路 1.71 KB
/
spec_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
# frozen_string_literal: true
def macos?
RUBY_PLATFORM[/darwin/]
end
def linux?
RUBY_PLATFORM[/linux/]
end
require "simplecov"
SimpleCov.start do
add_filter "/test/"
add_filter "/vendor/"
if macos?
minimum_coverage 100
else
minimum_coverage 97
end
end
PROJECT_ROOT ||= File.expand_path("..", __dir__)
STUB_PATH ||= File.expand_path(File.join(__FILE__, "..", "stub"))
$LOAD_PATH.unshift(STUB_PATH)
require "object"
require "os"
require "global"
require "bundle"
Dir.glob("#{PROJECT_ROOT}/lib/**/*.rb").each do |file|
next if file.include?("/extend/os/")
require file
end
formatters = [SimpleCov::Formatter::HTMLFormatter]
if macos? && ENV["COVERALLS_REPO_TOKEN"]
require "coveralls"
formatters << Coveralls::SimpleCov::Formatter
ENV["CI"] = "1"
ENV["CI_NAME"] = "github-actions"
ENV["CI_BUILD_NUMBER"] = ENV["GITHUB_REF"]
ENV["CI_BRANCH"] = ENV["HEAD_GITHUB_REF"]
%r{refs/pull/(?<pr>\d+)/merge} =~ ENV["GITHUB_REF"]
ENV["CI_PULL_REQUEST"] = pr
ENV["CI_BUILD_URL"] = "https://github.com/#{ENV["GITHUB_REPOSITORY"]}/pull/#{pr}/checks"
end
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(formatters)
require "bundler"
require "rspec/support/object_formatter"
RSpec.configure do |config|
config.filter_run_when_matching :focus
config.expect_with :rspec do |c|
c.max_formatted_output_length = 200
end
# Never truncate output objects.
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = nil
config.around do |example|
Bundler.with_clean_env { example.run }
end
config.before(:each, :needs_linux) do
skip "Not on Linux." unless linux?
end
config.before(:each, :needs_macos) do
skip "Not on macOS." unless macos?
end
end