Class: KnapsackPro::Pure::Queue::RSpecPure

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack_pro/pure/queue/rspec_pure.rb

Constant Summary collapse

FAILURE_EXIT_CODE =
1
FORMATTERS =
[
  'KnapsackPro::Formatters::TimeTracker',
]

Instance Method Summary collapse

Instance Method Details

#add_knapsack_pro_formatters_to(spec_opts) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/knapsack_pro/pure/queue/rspec_pure.rb', line 12

def add_knapsack_pro_formatters_to(spec_opts)
  return spec_opts unless spec_opts
  return spec_opts if FORMATTERS.all? { |formatter| spec_opts.include?(formatter) }

  FORMATTERS.each do |formatter|
    next if spec_opts.include?(formatter)
    spec_opts += " --format #{formatter}"
  end

  spec_opts
end

#args_with_seed_option_added_when_viable(order_option, seed, args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/knapsack_pro/pure/queue/rspec_pure.rb', line 28

def args_with_seed_option_added_when_viable(order_option, seed, args)
  return args if order_option && !order_option.include?('rand')
  return args if order_option && order_option.to_s.split(':')[1]

  return args unless seed.used?

  args + ['--seed', seed.value]
end

#error_exit_code(rspec_error_exit_code) ⇒ Object



24
25
26
# File 'lib/knapsack_pro/pure/queue/rspec_pure.rb', line 24

def error_exit_code(rspec_error_exit_code)
  rspec_error_exit_code || FAILURE_EXIT_CODE
end

#exit_summary(unexecuted_test_files) ⇒ Object



64
65
66
67
68
# File 'lib/knapsack_pro/pure/queue/rspec_pure.rb', line 64

def exit_summary(unexecuted_test_files)
  return if unexecuted_test_files.empty?

  "Unexecuted tests on this CI node (including pending tests): #{unexecuted_test_files.join(' ')}"
end

#prepare_cli_args(args, has_format_option, test_dir) ⇒ Object



37
38
39
40
41
# File 'lib/knapsack_pro/pure/queue/rspec_pure.rb', line 37

def prepare_cli_args(args, has_format_option, test_dir)
  (args || '').split
    .yield_self { args_with_at_least_one_formatter(_1, has_format_option) }
    .yield_self { args_with_default_options(_1, test_dir) }
end

#rspec_command(args, test_file_paths, scope) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/knapsack_pro/pure/queue/rspec_pure.rb', line 43

def rspec_command(args, test_file_paths, scope)
  messages = []
  return messages if test_file_paths.empty?

  case scope
  when :batch_finished
    messages << 'To retry the last batch of tests fetched from the Queue API, please run the following command on your machine:'
  when :queue_finished
    messages << 'To retry all the tests assigned to this CI node, please run the following command on your machine:'
  end

  stringified_cli_args = args.join(' ')
  FORMATTERS.each do |formatter|
    stringified_cli_args.sub!(" --format #{formatter}", '')
  end

  messages << "bundle exec rspec #{stringified_cli_args} " + KnapsackPro::TestFilePresenter.stringify_paths(test_file_paths)

  messages
end