red_dot 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +190 -0
- data/exe/rdot +9 -0
- data/lib/red_dot/app.rb +1169 -0
- data/lib/red_dot/cli.rb +41 -0
- data/lib/red_dot/config.rb +85 -0
- data/lib/red_dot/example_discovery.rb +87 -0
- data/lib/red_dot/rspec_result.rb +101 -0
- data/lib/red_dot/rspec_runner.rb +71 -0
- data/lib/red_dot/spec_discovery.rb +180 -0
- data/lib/red_dot/version.rb +5 -0
- data/lib/red_dot.rb +23 -0
- metadata +89 -0
data/lib/red_dot/cli.rb
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RedDot
|
|
4
|
+
class Cli
|
|
5
|
+
def self.parse(argv = ARGV)
|
|
6
|
+
args = argv.dup
|
|
7
|
+
overrides = {}
|
|
8
|
+
dir = nil
|
|
9
|
+
i = 0
|
|
10
|
+
while i < args.size
|
|
11
|
+
arg = args[i]
|
|
12
|
+
case arg
|
|
13
|
+
when '--format', '-f'
|
|
14
|
+
overrides[:format] = args[i + 1] if args[i + 1] && !args[i + 1].start_with?('-')
|
|
15
|
+
i += 2
|
|
16
|
+
when '--tag', '-t'
|
|
17
|
+
(overrides[:tags] ||= []) << args[i + 1] if args[i + 1] && !args[i + 1].start_with?('-')
|
|
18
|
+
i += 2
|
|
19
|
+
when '--out', '-o'
|
|
20
|
+
overrides[:out_path] = args[i + 1] if args[i + 1]
|
|
21
|
+
i += 2
|
|
22
|
+
when '--example', '-e'
|
|
23
|
+
overrides[:example_filter] = args[i + 1] if args[i + 1]
|
|
24
|
+
i += 2
|
|
25
|
+
when '--line', '-l'
|
|
26
|
+
overrides[:line_number] = args[i + 1] if args[i + 1] && !args[i + 1].start_with?('-')
|
|
27
|
+
i += 2
|
|
28
|
+
when '--fail-fast'
|
|
29
|
+
overrides[:fail_fast] = true
|
|
30
|
+
i += 1
|
|
31
|
+
when /^[^-]/
|
|
32
|
+
dir = arg
|
|
33
|
+
i += 1
|
|
34
|
+
else
|
|
35
|
+
i += 1
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
{ working_dir: dir || Dir.pwd, option_overrides: overrides }
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module RedDot
|
|
6
|
+
class Config
|
|
7
|
+
VALID_EDITORS = %w[vscode cursor textmate].freeze
|
|
8
|
+
|
|
9
|
+
DEFAULT_OPTIONS = {
|
|
10
|
+
tags: [],
|
|
11
|
+
tags_str: '',
|
|
12
|
+
format: 'progress',
|
|
13
|
+
out_path: '',
|
|
14
|
+
example_filter: '',
|
|
15
|
+
line_number: '',
|
|
16
|
+
fail_fast: false,
|
|
17
|
+
seed: '',
|
|
18
|
+
editor: 'cursor'
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
def self.user_config_path
|
|
22
|
+
base = ENV.fetch('XDG_CONFIG_HOME', File.join(Dir.home, '.config'))
|
|
23
|
+
File.join(base, 'red_dot', 'config.yml')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.project_config_path(working_dir)
|
|
27
|
+
File.join(File.expand_path(working_dir), '.red_dot.yml')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.load(working_dir: Dir.pwd)
|
|
31
|
+
opts = DEFAULT_OPTIONS.dup
|
|
32
|
+
project_path = project_config_path(working_dir)
|
|
33
|
+
if File.readable?(project_path)
|
|
34
|
+
opts = merge_file(opts, user_config_path)
|
|
35
|
+
opts = merge_file(opts, project_path)
|
|
36
|
+
end
|
|
37
|
+
opts
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.merge_file(opts, path)
|
|
41
|
+
return opts unless path && File.readable?(path)
|
|
42
|
+
|
|
43
|
+
raw = YAML.safe_load_file(path, permitted_classes: [Symbol])
|
|
44
|
+
return opts unless raw.is_a?(Hash)
|
|
45
|
+
|
|
46
|
+
opts = opts.dup
|
|
47
|
+
opts[:tags] = array_or_parse(opts[:tags], raw['tags'], raw['tags_str'])
|
|
48
|
+
opts[:tags_str] = raw['tags_str'].to_s.strip if raw.key?('tags_str')
|
|
49
|
+
opts[:tags_str] = (raw['tags'] || []).join(', ') if raw.key?('tags') && raw['tags'].is_a?(Array)
|
|
50
|
+
opts[:format] = raw['format'].to_s.strip if raw.key?('format') && !raw['format'].to_s.strip.empty?
|
|
51
|
+
opts[:out_path] = raw['output'].to_s if raw.key?('output')
|
|
52
|
+
opts[:out_path] = raw['out_path'].to_s if raw.key?('out_path') && !raw.key?('output')
|
|
53
|
+
opts[:example_filter] = raw['example_filter'].to_s if raw.key?('example_filter')
|
|
54
|
+
opts[:line_number] = raw['line_number'].to_s if raw.key?('line_number')
|
|
55
|
+
opts[:fail_fast] = raw['fail_fast'] ? true : false if raw.key?('fail_fast')
|
|
56
|
+
opts[:seed] = raw['seed'].to_s.strip if raw.key?('seed')
|
|
57
|
+
if raw.key?('editor')
|
|
58
|
+
val = raw['editor'].to_s.strip.downcase
|
|
59
|
+
opts[:editor] = val if VALID_EDITORS.include?(val)
|
|
60
|
+
end
|
|
61
|
+
opts
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.array_or_parse(existing, tags_val, tags_str_val)
|
|
65
|
+
if tags_val.is_a?(Array)
|
|
66
|
+
tags_val.map(&:to_s).reject(&:empty?)
|
|
67
|
+
elsif tags_str_val.to_s.strip != ''
|
|
68
|
+
tags_str_val.to_s.split(/[\s,]+/).map(&:strip).reject(&:empty?)
|
|
69
|
+
else
|
|
70
|
+
existing
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def self.component_roots(working_dir: Dir.pwd)
|
|
75
|
+
path = project_config_path(working_dir)
|
|
76
|
+
return nil unless File.readable?(path)
|
|
77
|
+
|
|
78
|
+
raw = YAML.safe_load_file(path, permitted_classes: [Symbol])
|
|
79
|
+
return nil unless raw.is_a?(Hash) && raw.key?('components')
|
|
80
|
+
return nil unless raw['components'].is_a?(Array)
|
|
81
|
+
|
|
82
|
+
raw['components'].map(&:to_s).reject(&:empty?)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'digest'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'tmpdir'
|
|
7
|
+
|
|
8
|
+
module RedDot
|
|
9
|
+
class ExampleDiscovery
|
|
10
|
+
ExampleInfo = Struct.new(:path, :line_number, :full_description, keyword_init: true)
|
|
11
|
+
|
|
12
|
+
CACHE_DIR = File.join(Dir.tmpdir, 'red_dot').freeze
|
|
13
|
+
|
|
14
|
+
def self.cache_file_path(working_dir)
|
|
15
|
+
hash = Digest::SHA256.hexdigest(File.expand_path(working_dir))[0, 16]
|
|
16
|
+
File.join(CACHE_DIR, "cache_#{hash}.json")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.read_cache_file(working_dir)
|
|
20
|
+
path = cache_file_path(working_dir)
|
|
21
|
+
return {} unless File.readable?(path)
|
|
22
|
+
|
|
23
|
+
raw = File.read(path)
|
|
24
|
+
return {} if raw.strip.empty?
|
|
25
|
+
|
|
26
|
+
data = JSON.parse(raw)
|
|
27
|
+
data['entries'] || {}
|
|
28
|
+
rescue JSON::ParserError, Errno::ENOENT
|
|
29
|
+
{}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.get_cached_examples(working_dir, path)
|
|
33
|
+
full_path = File.join(working_dir, path)
|
|
34
|
+
return nil unless File.exist?(full_path)
|
|
35
|
+
|
|
36
|
+
entries = read_cache_file(working_dir)
|
|
37
|
+
entry = entries[path]
|
|
38
|
+
return nil unless entry
|
|
39
|
+
|
|
40
|
+
current_mtime = File.mtime(full_path).to_f
|
|
41
|
+
return nil unless current_mtime == entry['mtime']
|
|
42
|
+
|
|
43
|
+
(entry['examples'] || []).map do |ex|
|
|
44
|
+
ExampleInfo.new(
|
|
45
|
+
path: ex['path'],
|
|
46
|
+
line_number: ex['line_number'],
|
|
47
|
+
full_description: ex['full_description'].to_s
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.write_cached_examples(working_dir, path, examples)
|
|
53
|
+
full_path = File.join(working_dir, path)
|
|
54
|
+
mtime = File.exist?(full_path) ? File.mtime(full_path).to_f : 0
|
|
55
|
+
entries = read_cache_file(working_dir)
|
|
56
|
+
entries[path] = {
|
|
57
|
+
'mtime' => mtime,
|
|
58
|
+
'examples' => examples.map do |e|
|
|
59
|
+
{ 'path' => e.path, 'line_number' => e.line_number, 'full_description' => e.full_description }
|
|
60
|
+
end
|
|
61
|
+
}
|
|
62
|
+
FileUtils.mkdir_p(CACHE_DIR)
|
|
63
|
+
File.write(cache_file_path(working_dir), JSON.generate({ 'entries' => entries }))
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def self.discover(working_dir:, path:)
|
|
67
|
+
json_path = RspecRunner.run_dry_run(working_dir: working_dir, paths: [path])
|
|
68
|
+
return [] unless json_path && File.readable?(json_path)
|
|
69
|
+
|
|
70
|
+
raw = File.read(json_path)
|
|
71
|
+
return [] if raw.strip.empty?
|
|
72
|
+
|
|
73
|
+
data = JSON.parse(raw)
|
|
74
|
+
examples = (data['examples'] || []).map do |ex|
|
|
75
|
+
ExampleInfo.new(
|
|
76
|
+
path: ex['file_path'],
|
|
77
|
+
line_number: ex['line_number'],
|
|
78
|
+
full_description: ex['full_description'].to_s
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
write_cached_examples(working_dir, path, examples)
|
|
82
|
+
examples
|
|
83
|
+
rescue JSON::ParserError, Errno::ENOENT
|
|
84
|
+
[]
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module RedDot
|
|
6
|
+
class RspecResult
|
|
7
|
+
Example = Struct.new(
|
|
8
|
+
:description, :full_description, :status, :file_path, :line_number, :exception_message,
|
|
9
|
+
:run_time, :pending_message, keyword_init: true
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
attr_reader :summary_line, :examples, :duration, :errors_outside_of_examples, :seed
|
|
13
|
+
|
|
14
|
+
def initialize(summary_line:, examples:, duration: nil, errors_outside_of_examples: 0, seed: nil)
|
|
15
|
+
@summary_line = summary_line
|
|
16
|
+
@examples = examples
|
|
17
|
+
@duration = duration
|
|
18
|
+
@errors_outside_of_examples = errors_outside_of_examples.to_i
|
|
19
|
+
@seed = seed
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.from_json_path(path)
|
|
23
|
+
return nil unless path && File.readable?(path)
|
|
24
|
+
|
|
25
|
+
raw = File.read(path)
|
|
26
|
+
return nil if raw.strip.empty?
|
|
27
|
+
|
|
28
|
+
data = JSON.parse(raw)
|
|
29
|
+
examples = (data['examples'] || []).map do |ex|
|
|
30
|
+
exception_msg = ex.dig('exception', 'message')
|
|
31
|
+
raw_run_time = ex['run_time']
|
|
32
|
+
run_time = if raw_run_time.is_a?(Numeric)
|
|
33
|
+
Float(raw_run_time)
|
|
34
|
+
elsif raw_run_time.is_a?(String) && !raw_run_time.strip.empty?
|
|
35
|
+
Float(raw_run_time)
|
|
36
|
+
end
|
|
37
|
+
Example.new(
|
|
38
|
+
description: ex['description'],
|
|
39
|
+
full_description: ex['full_description'],
|
|
40
|
+
status: ex['status']&.to_sym,
|
|
41
|
+
file_path: ex['file_path'],
|
|
42
|
+
line_number: ex['line_number'],
|
|
43
|
+
exception_message: exception_msg,
|
|
44
|
+
run_time: run_time,
|
|
45
|
+
pending_message: ex['pending_message']
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
summary = data['summary'] || {}
|
|
49
|
+
new(
|
|
50
|
+
summary_line: data['summary_line'] || '',
|
|
51
|
+
examples: examples,
|
|
52
|
+
duration: summary['duration'],
|
|
53
|
+
errors_outside_of_examples: summary['errors_outside_of_examples_count'],
|
|
54
|
+
seed: data['seed']
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def passed_count
|
|
59
|
+
examples.count { |e| e.status == :passed }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def failed_count
|
|
63
|
+
examples.count { |e| e.status == :failed }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def pending_count
|
|
67
|
+
examples.count { |e| e.status == :pending }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def failed_examples
|
|
71
|
+
examples.select { |e| e.status == :failed }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def pending_examples
|
|
75
|
+
examples.select { |e| e.status == :pending }
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def failure_locations
|
|
79
|
+
failed_examples.map { |e| e.line_number ? "#{e.file_path}:#{e.line_number}" : e.file_path }.uniq
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def examples_with_run_time
|
|
83
|
+
examples.select { |e| e.run_time.is_a?(Numeric) && e.run_time.positive? }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def slowest_examples(count = 5)
|
|
87
|
+
examples_with_run_time.max_by(count, &:run_time)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def fastest_examples(count = 5)
|
|
91
|
+
examples_with_run_time.min_by(count, &:run_time)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def slowest_files(count = 5)
|
|
95
|
+
by_file = examples_with_run_time.group_by(&:file_path)
|
|
96
|
+
by_file.transform_values { |exs| exs.sum(&:run_time) }
|
|
97
|
+
.max_by(count) { |_path, total| total }
|
|
98
|
+
.map { |path, total| [path, total] }
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'tempfile'
|
|
4
|
+
|
|
5
|
+
module RedDot
|
|
6
|
+
class RspecRunner
|
|
7
|
+
def self.spawn(working_dir:, paths:, tags: [], format: 'progress', out_path: nil,
|
|
8
|
+
example_filter: nil, fail_fast: false, seed: nil)
|
|
9
|
+
json_file = Tempfile.new(['red_dot', '.json'])
|
|
10
|
+
json_path = json_file.path
|
|
11
|
+
json_file.close
|
|
12
|
+
json_file.unlink
|
|
13
|
+
|
|
14
|
+
argv = build_argv(
|
|
15
|
+
paths: paths,
|
|
16
|
+
json_path: json_path,
|
|
17
|
+
format: format,
|
|
18
|
+
out_path: out_path,
|
|
19
|
+
tags: tags,
|
|
20
|
+
example_filter: example_filter,
|
|
21
|
+
fail_fast: fail_fast,
|
|
22
|
+
seed: seed
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
stdout_r, stdout_w = IO.pipe
|
|
26
|
+
stdout_w.close_on_exec = true
|
|
27
|
+
|
|
28
|
+
env = {}
|
|
29
|
+
env['BUNDLE_GEMFILE'] = File.join(working_dir, 'Gemfile') if File.file?(File.join(working_dir, 'Gemfile'))
|
|
30
|
+
|
|
31
|
+
cmd = rspec_command(working_dir)
|
|
32
|
+
pid = Kernel.spawn(env, *cmd, *argv, out: stdout_w, err: stdout_w, chdir: working_dir)
|
|
33
|
+
stdout_w.close
|
|
34
|
+
|
|
35
|
+
{ pid: pid, stdout_io: stdout_r, json_path: json_path }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.build_argv(paths:, json_path:, format: 'progress', out_path: nil, tags: [],
|
|
39
|
+
example_filter: nil, fail_fast: false, seed: nil)
|
|
40
|
+
argv = paths.dup
|
|
41
|
+
argv << '--format' << 'json' << '--out' << json_path
|
|
42
|
+
argv << '--format' << format
|
|
43
|
+
tags.each { |t| argv << '--tag' << t }
|
|
44
|
+
argv << '--out' << out_path if out_path.to_s.strip != ''
|
|
45
|
+
argv << '--example' << example_filter if example_filter.to_s.strip != ''
|
|
46
|
+
argv << '--fail-fast' if fail_fast
|
|
47
|
+
argv << '--seed' << seed.to_s.strip if seed.to_s.strip =~ /\A\d+\z/
|
|
48
|
+
argv
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.rspec_command(working_dir)
|
|
52
|
+
gemfile = File.join(working_dir, 'Gemfile')
|
|
53
|
+
File.file?(gemfile) ? %w[bundle exec rspec] : ['rspec']
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.run_dry_run(working_dir:, paths:)
|
|
57
|
+
json_file = Tempfile.new(['red_dot_list', '.json'])
|
|
58
|
+
json_path = json_file.path
|
|
59
|
+
json_file.close
|
|
60
|
+
json_file.unlink
|
|
61
|
+
argv = paths.dup
|
|
62
|
+
argv << '--dry-run' << '--format' << 'json' << '--out' << json_path
|
|
63
|
+
env = {}
|
|
64
|
+
env['BUNDLE_GEMFILE'] = File.join(working_dir, 'Gemfile') if File.file?(File.join(working_dir, 'Gemfile'))
|
|
65
|
+
cmd = rspec_command(working_dir)
|
|
66
|
+
pid = Kernel.spawn(env, *cmd, *argv, out: File::NULL, err: File::NULL, chdir: working_dir)
|
|
67
|
+
Process.wait(pid)
|
|
68
|
+
json_path
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pathname'
|
|
4
|
+
|
|
5
|
+
module RedDot
|
|
6
|
+
class SpecDiscovery
|
|
7
|
+
DEFAULT_SPEC_DIR = 'spec'
|
|
8
|
+
DEFAULT_PATTERN = '**/*_spec.rb'
|
|
9
|
+
COMPONENTS_DIR = 'components'
|
|
10
|
+
|
|
11
|
+
def initialize(working_dir: Dir.pwd)
|
|
12
|
+
@working_dir = File.expand_path(working_dir)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def umbrella?
|
|
16
|
+
components_dir = File.join(@working_dir, COMPONENTS_DIR)
|
|
17
|
+
File.directory?(components_dir)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def component_roots
|
|
21
|
+
return [] unless umbrella?
|
|
22
|
+
|
|
23
|
+
explicit = Config.component_roots(working_dir: @working_dir)
|
|
24
|
+
return explicit.map { |r| r == '.' ? '' : r } if explicit&.any?
|
|
25
|
+
|
|
26
|
+
roots = []
|
|
27
|
+
root_spec_dir = spec_dir_for_root
|
|
28
|
+
roots << '' if root_spec_dir && Dir.exist?(File.join(@working_dir, root_spec_dir))
|
|
29
|
+
|
|
30
|
+
comp_dir = File.join(@working_dir, COMPONENTS_DIR)
|
|
31
|
+
return roots unless Dir.exist?(comp_dir)
|
|
32
|
+
|
|
33
|
+
Dir.children(comp_dir).each do |name|
|
|
34
|
+
next unless File.directory?(File.join(comp_dir, name))
|
|
35
|
+
|
|
36
|
+
comp_path = "#{COMPONENTS_DIR}/#{name}"
|
|
37
|
+
comp_spec = File.join(@working_dir, comp_path, DEFAULT_SPEC_DIR)
|
|
38
|
+
roots << comp_path if Dir.exist?(comp_spec)
|
|
39
|
+
end
|
|
40
|
+
roots.sort
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def spec_dir
|
|
44
|
+
if umbrella?
|
|
45
|
+
return File.join(@working_dir, DEFAULT_SPEC_DIR) if component_roots.empty?
|
|
46
|
+
|
|
47
|
+
first = component_roots.first
|
|
48
|
+
base = first.empty? ? @working_dir : File.join(@working_dir, first)
|
|
49
|
+
spec_subdir = read_default_path_from_rspec(base) || DEFAULT_SPEC_DIR
|
|
50
|
+
return File.join(base, spec_subdir)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
path = read_default_path_from_rspec(@working_dir)
|
|
54
|
+
base = path || DEFAULT_SPEC_DIR
|
|
55
|
+
File.join(@working_dir, base)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def relative_spec_path
|
|
59
|
+
read_default_path_from_rspec(@working_dir) || DEFAULT_SPEC_DIR
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def discover
|
|
63
|
+
if umbrella?
|
|
64
|
+
discover_umbrella
|
|
65
|
+
else
|
|
66
|
+
discover_single
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def discover_grouped_by_dir
|
|
71
|
+
files = discover
|
|
72
|
+
files.group_by { |f| File.dirname(f) }.transform_values(&:sort)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def run_context_for(display_path)
|
|
76
|
+
if umbrella?
|
|
77
|
+
run_context_umbrella(display_path)
|
|
78
|
+
else
|
|
79
|
+
{ run_cwd: @working_dir, rspec_path: display_path }
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def default_run_all_paths
|
|
84
|
+
if umbrella?
|
|
85
|
+
flat_spec_list_for_umbrella
|
|
86
|
+
else
|
|
87
|
+
[relative_spec_path]
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def empty_state_message
|
|
92
|
+
if umbrella? && component_roots.empty?
|
|
93
|
+
"No spec directory or components with spec/ found in #{@working_dir}"
|
|
94
|
+
else
|
|
95
|
+
"No spec files in #{spec_dir}"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
def spec_dir_for_root
|
|
102
|
+
read_default_path_from_rspec(@working_dir) || DEFAULT_SPEC_DIR
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def read_default_path_from_rspec(dir)
|
|
106
|
+
rspec_file = File.join(dir, '.rspec')
|
|
107
|
+
return nil unless File.readable?(rspec_file)
|
|
108
|
+
|
|
109
|
+
line = File.readlines(rspec_file).find { |l| l.strip.start_with?('--default-path') }
|
|
110
|
+
return nil unless line
|
|
111
|
+
|
|
112
|
+
line.sub(/\A--default-path\s+/, '').strip
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def discover_single
|
|
116
|
+
dir = spec_dir
|
|
117
|
+
return [] unless dir && Dir.exist?(dir)
|
|
118
|
+
|
|
119
|
+
pattern = File.join(dir, DEFAULT_PATTERN)
|
|
120
|
+
Dir.glob(pattern).map { |p| Pathname.new(p).relative_path_from(Pathname.new(@working_dir)).to_s }.sort
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def discover_umbrella
|
|
124
|
+
roots = component_roots
|
|
125
|
+
return [] if roots.empty?
|
|
126
|
+
|
|
127
|
+
files = []
|
|
128
|
+
roots.each do |component_root|
|
|
129
|
+
base = component_root.empty? ? @working_dir : File.join(@working_dir, component_root)
|
|
130
|
+
spec_path = read_default_path_from_rspec(base) || DEFAULT_SPEC_DIR
|
|
131
|
+
spec_full = File.join(base, spec_path)
|
|
132
|
+
next unless Dir.exist?(spec_full)
|
|
133
|
+
|
|
134
|
+
pattern = File.join(spec_full, DEFAULT_PATTERN)
|
|
135
|
+
Dir.glob(pattern).each do |p|
|
|
136
|
+
rel = Pathname.new(p).relative_path_from(Pathname.new(@working_dir)).to_s
|
|
137
|
+
files << rel
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
files.sort
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def flat_spec_list_for_umbrella
|
|
144
|
+
discover
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def run_context_umbrella(display_path)
|
|
148
|
+
path_str = display_path.to_s
|
|
149
|
+
line_suffix = nil
|
|
150
|
+
if path_str =~ /\A(.+):(\d+)\z/
|
|
151
|
+
path_str = Regexp.last_match(1)
|
|
152
|
+
line_suffix = ":#{Regexp.last_match(2)}"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
roots = component_roots
|
|
156
|
+
roots_with_prefix = roots.map do |r|
|
|
157
|
+
base = r.empty? ? @working_dir : File.join(@working_dir, r)
|
|
158
|
+
spec_subdir = read_default_path_from_rspec(base) || DEFAULT_SPEC_DIR
|
|
159
|
+
prefix = r.empty? ? "#{spec_subdir}/" : "#{r}/#{spec_subdir}/"
|
|
160
|
+
[r, prefix]
|
|
161
|
+
end
|
|
162
|
+
roots_with_prefix.sort_by! { |_r, p| -p.length }
|
|
163
|
+
|
|
164
|
+
roots_with_prefix.each do |component_root, prefix|
|
|
165
|
+
next unless path_str == prefix.chomp('/') || path_str.start_with?(prefix)
|
|
166
|
+
|
|
167
|
+
run_cwd = component_root.empty? ? @working_dir : File.join(@working_dir, component_root)
|
|
168
|
+
rspec_path = if component_root.empty?
|
|
169
|
+
path_str
|
|
170
|
+
else
|
|
171
|
+
path_str.sub(%r{\A#{Regexp.escape(component_root)}/?}, '')
|
|
172
|
+
end
|
|
173
|
+
rspec_path += line_suffix if line_suffix
|
|
174
|
+
return { run_cwd: run_cwd, rspec_path: rspec_path }
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
{ run_cwd: @working_dir, rspec_path: display_path }
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
data/lib/red_dot.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'red_dot/version'
|
|
4
|
+
require_relative 'red_dot/config'
|
|
5
|
+
require_relative 'red_dot/cli'
|
|
6
|
+
require_relative 'red_dot/spec_discovery'
|
|
7
|
+
require_relative 'red_dot/example_discovery'
|
|
8
|
+
require_relative 'red_dot/rspec_result'
|
|
9
|
+
require_relative 'red_dot/rspec_runner'
|
|
10
|
+
require_relative 'red_dot/app'
|
|
11
|
+
|
|
12
|
+
module RedDot
|
|
13
|
+
class Error < StandardError; end
|
|
14
|
+
|
|
15
|
+
def self.run(working_dir: Dir.pwd, option_overrides: {})
|
|
16
|
+
unless $stdout.tty?
|
|
17
|
+
warn 'Error: red_dot (rdot) requires a TTY. Run from a terminal.'
|
|
18
|
+
exit 1
|
|
19
|
+
end
|
|
20
|
+
app = RedDot::App.new(working_dir: working_dir, option_overrides: option_overrides)
|
|
21
|
+
Bubbletea.run(app, alt_screen: true)
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: red_dot
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Lovell McIlwain
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-03-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bubbletea
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: lipgloss
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.1'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.1'
|
|
41
|
+
description: |-
|
|
42
|
+
A lazy-like TUI for running RSpec tests: select files, set options (tags, format, output, seed), " \
|
|
43
|
+
"run all/some/one, view results, and rerun.
|
|
44
|
+
email:
|
|
45
|
+
- ''
|
|
46
|
+
executables:
|
|
47
|
+
- rdot
|
|
48
|
+
extensions: []
|
|
49
|
+
extra_rdoc_files: []
|
|
50
|
+
files:
|
|
51
|
+
- LICENSE
|
|
52
|
+
- README.md
|
|
53
|
+
- exe/rdot
|
|
54
|
+
- lib/red_dot.rb
|
|
55
|
+
- lib/red_dot/app.rb
|
|
56
|
+
- lib/red_dot/cli.rb
|
|
57
|
+
- lib/red_dot/config.rb
|
|
58
|
+
- lib/red_dot/example_discovery.rb
|
|
59
|
+
- lib/red_dot/rspec_result.rb
|
|
60
|
+
- lib/red_dot/rspec_runner.rb
|
|
61
|
+
- lib/red_dot/spec_discovery.rb
|
|
62
|
+
- lib/red_dot/version.rb
|
|
63
|
+
homepage: https://github.com/vmcilwain/red_dot
|
|
64
|
+
licenses:
|
|
65
|
+
- MIT
|
|
66
|
+
metadata:
|
|
67
|
+
homepage_uri: https://github.com/vmcilwain/red_dot
|
|
68
|
+
source_code_uri: https://github.com/vmcilwain/red_dot
|
|
69
|
+
rubygems_mfa_required: 'true'
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: 3.2.0
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubygems_version: 3.5.16
|
|
86
|
+
signing_key:
|
|
87
|
+
specification_version: 4
|
|
88
|
+
summary: Terminal UI for running RSpec tests (hopefully easier)
|
|
89
|
+
test_files: []
|