Class: Smartest::CLIArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/smartest/cli_arguments.rb

Constant Summary collapse

DEFAULT_PROFILE_COUNT =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLIArguments

Returns a new instance of CLIArguments.



11
12
13
14
15
16
17
18
19
# File 'lib/smartest/cli_arguments.rb', line 11

def initialize(argv)
  @files = []
  @whole_files = Set.new
  @line_filters = Hash.new { |hash, key| hash[key] = Set.new }
  @profile_count = nil

  paths = extract_options(argv)
  parse_paths(paths.empty? ? ["smartest/**/*_test.rb"] : paths)
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



9
10
11
# File 'lib/smartest/cli_arguments.rb', line 9

def files
  @files
end

#line_filtersObject (readonly)

Returns the value of attribute line_filters.



9
10
11
# File 'lib/smartest/cli_arguments.rb', line 9

def line_filters
  @line_filters
end

#profile_countObject (readonly)

Returns the value of attribute profile_count.



9
10
11
# File 'lib/smartest/cli_arguments.rb', line 9

def profile_count
  @profile_count
end

Instance Method Details

#filter_tests?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/smartest/cli_arguments.rb', line 21

def filter_tests?
  @line_filters.any?
end

#select_tests(tests) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smartest/cli_arguments.rb', line 25

def select_tests(tests)
  return tests unless filter_tests?

  tests.select do |test_case|
    next false unless test_case.location

    path = File.expand_path(test_case.location.path)
    @whole_files.include?(path) ||
      @line_filters.fetch(path, []).any? { |line_filter| test_case.includes_line_range?(line_filter) }
  end
end