Class: DeltaTest::CLI::ExecCommand

Inherits:
CommandBase show all
Defined in:
lib/delta_test/cli/exec_command.rb

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!

Constructor Details

This class inherits a constructor from DeltaTest::CLI::CommandBase

Instance Method Details

#extract_arg_filesObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/delta_test/cli/exec_command.rb', line 51

def extract_arg_files
  @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_filesObject



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
  extract_arg_files
  filter_spec_files
  run_command
end

#listObject



23
24
25
# File 'lib/delta_test/cli/exec_command.rb', line 23

def list
  @list ||= RelatedSpecList.new
end

#profile_mode?Boolean

Returns:

  • (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_filesObject



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
  # force profile mode cuz we don't have a table
  @profile_mode = true
end

#run_commandObject



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

#statsObject



19
20
21
# File 'lib/delta_test/cli/exec_command.rb', line 19

def stats
  @stats ||= Stats.new
end