forked from fastlane/fastlane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
123 lines (107 loc) · 4.32 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
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
# This module is only used to check the environment is currently a testing env
module SpecHelper
end
require "coveralls"
Coveralls.wear! unless ENV["FASTLANE_SKIP_UPDATE_CHECK"]
require "webmock/rspec"
WebMock.disable_net_connect!(allow: 'coveralls.io')
require "fastlane"
UI = FastlaneCore::UI
unless ENV["DEBUG"]
fastlane_tests_tmpdir = "#{Dir.tmpdir}/fastlane_tests"
$stdout.puts("Changing stdout to #{fastlane_tests_tmpdir}, set `DEBUG` environment variable to print to stdout (e.g. when using `pry`)")
$stdout = File.open(fastlane_tests_tmpdir, "w")
end
if FastlaneCore::Helper.is_mac?
xcode_path = FastlaneCore::Helper.xcode_path
unless xcode_path.include?("Contents/Developer")
UI.error("Seems like you didn't set the developer tools path correctly")
UI.error("Detected path '#{xcode_path}'") if xcode_path.to_s.length > 0
UI.error("Please run the following on your machine")
UI.command("sudo xcode-select -s /Applications/Xcode.app")
UI.error("Adapt the path if you have Xcode installed/named somewhere else")
exit(1)
end
end
(Fastlane::TOOLS + [:spaceship, :fastlane_core]).each do |tool|
path = File.join(tool.to_s, "spec", "spec_helper.rb")
require_relative path if File.exist?(path)
require tool.to_s
end
my_main = self
RSpec.configure do |config|
config.before(:each) do |current_test|
# We don't want to call the RubyGems API at any point
# This was a request that was added with Ruby 2.4.0
allow(Fastlane::FastlaneRequire).to receive(:install_gem_if_needed).and_return(nil)
ENV['FASTLANE_PLATFORM_NAME'] = nil
tool_name = current_test.id.match(%r{\.\/(\w+)\/})[1]
method_name = "before_each_#{tool_name}".to_sym
begin
my_main.send(method_name)
rescue NoMethodError
# no method implemented
end
end
config.after(:each) do |current_test|
tool_name = current_test.id.match(%r{\.\/(\w+)\/})[1]
method_name = "after_each_#{tool_name}".to_sym
begin
my_main.send(method_name)
rescue NoMethodError
# no method implemented
end
end
config.example_status_persistence_file_path = "/tmp/rspec_failed_tests.txt"
# skip some tests if not running on mac
unless FastlaneCore::Helper.is_mac?
# define metadata tags that also imply :skip
config.define_derived_metadata(:requires_xcode) do |meta|
meta[:skip] = "Skipped: Requires Xcode to be installed (which is not possible on this platform and no workaround has been implemented)"
end
config.define_derived_metadata(:requires_xcodebuild) do |meta|
meta[:skip] = "Skipped: Requires `xcodebuild` to be installed (which is not possible on this platform and no workaround has been implemented)"
end
config.define_derived_metadata(:requires_plistbuddy) do |meta|
meta[:skip] = "Skipped: Requires `plistbuddy` to be installed (which is not possible on this platform and no workaround has been implemented)"
end
config.define_derived_metadata(:requires_keychain) do |meta|
meta[:skip] = "Skipped: Requires `keychain` to be installed (which is not possible on this platform and no workaround has been implemented)"
end
config.define_derived_metadata(:requires_security) do |meta|
meta[:skip] = "Skipped: Requires `security` to be installed (which is not possible on this platform and no workaround has been implemented)"
end
# also skip `before()` for test groups that are skipped because of their tags
# only works for `describe` groups (that are parents of the `before`, not if the tag is set on `it`
# caution! has unexpected side effect on usage of `skip: false` for individual examples
# see https://groups.google.com/d/msg/rspec/5qeKQr_7G7k/Pb3ss2hOAAAJ
module HookOverrides
def before(*args)
super unless metadata[:skip]
end
end
config.extend(HookOverrides)
end
end
module FastlaneSpec
module Env
# a wrapper to temporarily modify the values of ARGV to
# avoid errors like: "warning: already initialized constant ARGV"
# if no block is given, modifies ARGV for good
# rubocop:disable Style/MethodName
def self.with_ARGV(argv)
copy = ARGV.dup
ARGV.clear
ARGV.concat(argv)
if block_given?
begin
yield
ensure
ARGV.clear
ARGV.concat(copy)
end
end
end
# rubocop:enable Style/MethodName
end
end