Class: Rdm::SpecRunner::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rdm/spec_runner/runner.rb

Constant Summary collapse

RUNIGNORE_PATH =
'tests/.runignore'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package: nil, spec_matcher: nil, path: nil, show_missing_packages: true, skip_ignored_packages: false) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rdm/spec_runner/runner.rb', line 8

def initialize(
  package:               nil, 
  spec_matcher:          nil, 
  path:                  nil, 
  show_missing_packages: true,
  skip_ignored_packages: false
)
  @package               = package,
  @spec_matcher          = spec_matcher.to_s
  @no_specs_packages     = []
  @path                  = path
  @run_all               = @package.nil?
  @show_missing_packages = show_missing_packages
  @skip_ignored_packages = skip_ignored_packages
  @skipped_packages      = []
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



6
7
8
# File 'lib/rdm/spec_runner/runner.rb', line 6

def command
  @command
end

#no_specs_packagesObject

Returns the value of attribute no_specs_packages.



4
5
6
# File 'lib/rdm/spec_runner/runner.rb', line 4

def no_specs_packages
  @no_specs_packages
end

#prepared_command_paramsObject

Returns the value of attribute prepared_command_params.



5
6
7
# File 'lib/rdm/spec_runner/runner.rb', line 5

def prepared_command_params
  @prepared_command_params
end

Instance Method Details

#check_input_params!Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rdm/spec_runner/runner.rb', line 53

def check_input_params!
  if @package_name
    unless is_package_included?(@package_name)
      exit_with_message(
        view.package_not_found_message(@package_name, prepared_command_params)
      )
    end

    if no_specs_packages.include?(@package_name)
      exit_with_message(
        view.no_specs_for_package(@package_name)
      )
    end
  end
end

#display_ignored_specsObject



151
152
153
154
155
# File 'lib/rdm/spec_runner/runner.rb', line 151

def display_ignored_specs
  if !@skipped_packages.empty?
    print_message view.skipping_specs_message(@skipped_packages)
  end
end

#display_missing_specsObject



145
146
147
148
149
# File 'lib/rdm/spec_runner/runner.rb', line 145

def display_missing_specs
  if !no_specs_packages.empty?
    print_message view.missing_specs_message(no_specs_packages)
  end
end

#execute_commandObject



157
158
159
160
161
162
# File 'lib/rdm/spec_runner/runner.rb', line 157

def execute_command
  eval(command)
  if !$?.success?
    exit(1)
  end
end

#exit_with_message(msg) ⇒ Object



48
49
50
51
# File 'lib/rdm/spec_runner/runner.rb', line 48

def exit_with_message(msg)
  print_message(msg)
  exit 1
end

#is_package_included?(package_name) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/rdm/spec_runner/runner.rb', line 69

def is_package_included?(package_name)
  !prepared_command_params.select do |x|
    x.package_name == package_name
  end.empty?
end

#packagesObject



35
36
37
# File 'lib/rdm/spec_runner/runner.rb', line 35

def packages
  @packages ||= Rdm::SpecRunner::PackageFetcher.new(@path).packages
end

#prepare!Object



75
76
77
78
79
80
81
82
# File 'lib/rdm/spec_runner/runner.rb', line 75

def prepare!
  prepared_command_params = []
  no_specs_packages       = []
  command                 = nil
  prepare_command_params
  prepare_no_specs_packages
  prepare_command
end

#prepare_commandObject



100
101
102
103
104
105
106
107
108
# File 'lib/rdm/spec_runner/runner.rb', line 100

def prepare_command
  @command ||= begin
    if @package_name
      prepare_single_package_command(@package_name)
    else
      prepare_command_for_packages(prepared_command_params)
    end
  end
end

#prepare_command_for_packages(packages_command_params) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rdm/spec_runner/runner.rb', line 117

def prepare_command_for_packages(packages_command_params)
  if @skip_ignored_packages
    runignore_path = File.expand_path(File.join(Rdm.root_dir, RUNIGNORE_PATH))
    package_list   = Rdm::SourceParser.read_and_init_source(Rdm.root).packages.keys

    skipped_package_list = File.read(runignore_path)
      .lines
      .map(&:strip)
      .reject(&:empty?) rescue  []
    
    @skipped_packages = skipped_package_list.reject {|line| !package_list.include?(line)}
    invalid_ignore_packages = skipped_package_list - @skipped_packages

    if !invalid_ignore_packages.empty?
      puts "WARNING: #{RUNIGNORE_PATH} contains invalid package names: #{invalid_ignore_packages.inspect}"
    end
  else
    @skipped_packages = []
  end

  packages_command_params
    .select  { |cmd_params| cmd_params.spec_count > 0 }
    .reject  { |cmd_params| @skipped_packages.include?(cmd_params.package_name) }
    .sort_by { |cmd_params| - cmd_params.spec_count }
    .map(&:command)
    .join(' && ')
end

#prepare_command_paramsObject



84
85
86
87
88
89
90
91
92
# File 'lib/rdm/spec_runner/runner.rb', line 84

def prepare_command_params
  @prepared_command_params ||= begin
    packages.map do |_name, package|
      Rdm::SpecRunner::CommandGenerator.new(
        package_name: package.name, package_path: package.path, spec_matcher: @spec_matcher
      ).generate
    end
  end
end

#prepare_no_specs_packagesObject



94
95
96
97
98
# File 'lib/rdm/spec_runner/runner.rb', line 94

def prepare_no_specs_packages
  prepared_command_params
    .select { |cp| cp.spec_count == 0 }
    .map { |cp| no_specs_packages << cp.package_name }
end

#prepare_single_package_command(package_name) ⇒ Object



110
111
112
113
114
115
# File 'lib/rdm/spec_runner/runner.rb', line 110

def prepare_single_package_command(package_name)
  selected = prepared_command_params.select do |cmd_params|
    cmd_params.package_name == package_name
  end
  prepare_command_for_packages(selected)
end


43
44
45
46
# File 'lib/rdm/spec_runner/runner.rb', line 43

def print_message(msg)
  puts msg
  true
end

#runObject



25
26
27
28
29
30
31
32
33
# File 'lib/rdm/spec_runner/runner.rb', line 25

def run
  prepare!
  check_input_params!
  display_missing_specs if @show_missing_packages
  display_ignored_specs if @skip_ignored_packages
  print_message view.specs_header_message if @show_missing_packages || @skip_ignored_packages
  
  execute_command
end

#viewObject



39
40
41
# File 'lib/rdm/spec_runner/runner.rb', line 39

def view
  @view ||= Rdm::SpecRunner::View.new
end