Class: DeltaTest::CLI::ExecCommand
Constant Summary
collapse
- BUNDLE_EXEC =
['bundle', 'exec'].map(&:freeze).freeze
- SPLITTER =
'--'.freeze
Constants inherited
from CommandBase
CommandBase::DEFAULT_OPTIONS
Instance Method Summary
collapse
Methods inherited from CommandBase
#bundler_enabled?, #exec_with_data, #exit_with_message, #initialize, #invoke, #parse_options!
Instance Method Details
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/delta_test/cli/exec_command.rb', line 51
def
@args.map! { |arg| Shellwords.escape(arg) }
splitter = @args.index(SPLITTER)
return unless splitter
@arg_files = @args.drop(splitter + 1)
if @arg_files && @arg_files.any?
@args = @args.take(splitter)
else
@arg_files = nil
end
end
|
#filter_spec_files ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/delta_test/cli/exec_command.rb', line 65
def filter_spec_files
return unless @arg_files
if @spec_files
pattern = @arg_files.map { |file| Regexp.escape(file) }
pattern = '^(%s)' % pattern.join('|')
@spec_files = @spec_files.grep(pattern)
else
@spec_files = @arg_files
end
end
|
#invoke! ⇒ Object
12
13
14
15
16
17
|
# File 'lib/delta_test/cli/exec_command.rb', line 12
def invoke!
retrive_spec_files
filter_spec_files
run_command
end
|
#list ⇒ Object
23
24
25
|
# File 'lib/delta_test/cli/exec_command.rb', line 23
def list
@list ||= RelatedSpecList.new
end
|
#profile_mode? ⇒ Boolean
27
28
29
30
|
# File 'lib/delta_test/cli/exec_command.rb', line 27
def profile_mode?
return @profile_mode if defined?(@profile_mode)
@profile_mode = !stats.base_commit || !!@options['force']
end
|
#retrive_spec_files ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/delta_test/cli/exec_command.rb', line 32
def retrive_spec_files
return if profile_mode?
puts 'Base commit: %s' % [stats.base_commit]
puts
list.load_table!(stats.table_file_path)
list.retrive_changed_files!(stats.base_commit)
@spec_files = list.related_spec_files.to_a
if @spec_files.empty?
exit_with_message(0, 'Nothing to test')
end
rescue TableNotFoundError
@profile_mode = true
end
|
#run_command ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/delta_test/cli/exec_command.rb', line 77
def run_command
args = []
if profile_mode?
args << ('%s=%s' % [VERBOSE_FLAG, true]) if DeltaTest.verbose?
args << ('%s=%s' % [ACTIVE_FLAG, true])
end
if @spec_files
args.unshift('cat', '|')
args << 'xargs'
end
if bundler_enabled? && BUNDLE_EXEC != @args.take(2)
args += BUNDLE_EXEC
end
args += @args
exec_with_data(args.join(' '), @spec_files)
end
|
#stats ⇒ Object
19
20
21
|
# File 'lib/delta_test/cli/exec_command.rb', line 19
def stats
@stats ||= Stats.new
end
|