-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
rspec
executable file
路59 lines (49 loc) 路 1.48 KB
/
rspec
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
#!/usr/bin/env ruby
ROOT = File.expand_path('..', __dir__)
LIBS = %w[
admin
api
backend
core
sample
legacy_promotions
]
# Ignore line info, e.g. foo/bar.rb:123 would become foo/bar.rb
without_line = ->(path) { path.split(':', 2).first }
# Is it a spec file or a CLI option?
is_spec = ->(path) {
File.directory?(path) ? path.include?('/spec') : without_line[path].end_with?('_spec.rb')
}
# Find the Solidus library for this path
find_lib = ->(path) {
path = without_line[path]
LIBS.find { |lib| path.start_with? File.join(ROOT, lib) +'/' }
}
# Let all paths be absolute, if the file is missing try prepending one of the LIBS,
# this allows calling `bin/rspec spec/api/foo/bar_spec.rb` without needing to add
# the api/ prefix.
expand_existing = ->(path) {
[
File.expand_path(path),
*LIBS.map { |l| File.expand_path(path, l) }
].find { |p| File.exist?(without_line[p]) }
}
spec_files, options = ARGV.partition(&is_spec) # Separate specs and options
specs = {}
if spec_files.any?
specs = spec_files.map do |f|
expand_existing[f] or abort "Couldn't find spec file: #{f.inspect}"
end.group_by(&find_lib)
else
# If no files are provided run all specs in each lib.
LIBS.each { |lib| specs[lib] = [] }
end
# Run specs for each lib separately
specs.each do |lib, files|
Dir.chdir(lib) do
command = ['bundle', 'exec', 'rspec', *options, *files]
warn "$ cd #{lib}; #{command.join(' ')}; cd -"
system *command
exit $?.exitstatus unless $?.success?
end
end