pork 1.5.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pork/isolate.rb DELETED
@@ -1,98 +0,0 @@
1
-
2
- module Pork
3
- module Isolate
4
- def all_tests
5
- @all_tests ||= build_all_tests
6
- end
7
-
8
- def all_paths
9
- (all_tests[:files] || {}).values.flat_map(&:values).flatten(1).uniq
10
- end
11
-
12
- def [] index
13
- by_groups(index) || by_source(index)
14
- end
15
-
16
- def by_groups groups
17
- return unless tests = all_tests[:groups]
18
- paths = groups.split(',').flat_map do |g|
19
- tests[g.strip] || []
20
- end.uniq
21
- paths unless paths.empty?
22
- end
23
-
24
- def by_source source
25
- return unless tests = all_tests[:files]
26
- file_str, line_str = source.split(':')
27
- file, line = File.expand_path(file_str), line_str.to_i
28
- return unless cases = tests[file]
29
- if line.zero?
30
- cases.values.flatten(1).uniq
31
- else
32
- _, paths = cases.reverse_each.find{ |(l, _)| l <= line }
33
- paths
34
- end
35
- end
36
-
37
- protected
38
- def isolate stat, path, super_env=nil
39
- env = Env.new(super_env)
40
- idx = path.first
41
-
42
- @tests.first(idx).each do |(type, arg, _)|
43
- case type
44
- when :before
45
- env.before << arg
46
- when :after
47
- env.after << arg
48
- end
49
- end
50
-
51
- if path.size == 1
52
- _, desc, test = @tests[idx]
53
- run(stat, desc, test, env)
54
- else
55
- @tests[idx][1].isolate(stat, path.drop(1), env)
56
- end
57
-
58
- stat
59
- end
60
-
61
- def build_all_tests result={}, path=[]
62
- @tests.each_with_index.inject(result) do |r,
63
- ((type, imp, test, opts),
64
- index)|
65
- current = path + [index]
66
-
67
- case type
68
- when :describe
69
- imp.build_all_tests(r, current) do |nested|
70
- store_path(r, nested, test, opts[:groups])
71
- end
72
- when :would
73
- yield(current) if block_given?
74
- store_path(r, current, test, opts[:groups])
75
- end
76
-
77
- r
78
- end
79
- end
80
-
81
- def store_path tests, path, test, groups
82
- store_for_groups(tests, path, groups) if groups
83
- store_for_source(tests, path, *test.source_location)
84
- end
85
-
86
- def store_for_groups tests, path, groups
87
- r = tests[:groups] ||= {}
88
- groups.each do |g|
89
- (r[g.to_s] ||= []) << path
90
- end
91
- end
92
-
93
- def store_for_source tests, path, file, line
94
- r = tests[:files] ||= {}
95
- ((r[File.expand_path(file)] ||= {})[line] ||= []) << path
96
- end
97
- end
98
- end