-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathtest_skip.rb
63 lines (55 loc) · 1.43 KB
/
test_skip.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
# Including this module allows `omit` test cases based on an external file, not in the source code
#
# The file contains a list of the names of the test cases to skip:
#
# ```
# test_foo(RBS::UnitTest) # Test case name
# RBS::CLICtest # Test class name
# test_collection_install(CLITest) requires bundler setup # Can have comments
# ```
#
# And start tests with `$RBS_SKIP_TESTS` env var:
#
# ```
# $ RBS_SKIP_TESTS=../rbs_skip_tests rake test
# ```
#
module TestSkip
env = ENV["RBS_SKIP_TESTS"]
SKIP_TESTS_FILE =
if env
Pathname(env)
end
SKIP_TESTS =
if SKIP_TESTS_FILE
SKIP_TESTS_FILE.each_line.with_object({}) do |line, hash|
line.chomp!
line.gsub!(/#.*/, "")
line.strip!
next if line.empty?
name, message = line.split(/\s+/, 2)
hash[name] = message
end
end
if SKIP_TESTS
def setup
super
if SKIP_TESTS.key?(name) || SKIP_TESTS.key?(self.class.name)
if message = SKIP_TESTS[name] || SKIP_TESTS[self.class.name]
omit "Skip test by RBS_SKIP_TESTS(#{SKIP_TESTS_FILE}): #{message}"
else
omit "Skip test by RBS_SKIP_TESTS(#{SKIP_TESTS_FILE})"
end
end
end
def teardown
case
when passed?
# nop
else
puts "💡You can skip this test `#{name}` by adding the name to `#{SKIP_TESTS_FILE}`"
end
super
end
end
end