Class: Cbratest::Runner

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

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Runner

Returns a new instance of Runner.



11
12
13
14
15
# File 'lib/cobratest.rb', line 11

def initialize(opts)
  @verbose_output = opts[:display] == "verbose"
  @since = opts[:since] || "current branch"
  @test_runner = opts[:runner] || "test.sh"
end

Instance Method Details

#run(root_path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cobratest.rb', line 17

def run(root_path)
  path = root_path || current_path
  app = GemfileScraper.new(path)

  outputs "All components"
  cobra_deps = app.transitive_cobra_dependencies.to_set
  components = cobra_deps << app.to_s
  outputs component_out(components.to_a)

  outputs "\nChanges since last commit on #{@since}"
  root_dir = `cd "#{path}" && git rev-parse --show-toplevel`.chomp
  if @since != "current branch"
    changes = `cd "#{root_dir}" && git diff --name-only #{@since}`.split("\n").map { |file| File.join(root_dir, file) }
  else
    changes = `cd "#{root_dir}" && git status -s -u`.split("\n").map { |file| File.join(root_dir, file.sub(/^.../, "")) }
  end
  outputs changes

  outputs "\nDirectly affected components"
  affected = AffectedComponentFinder.new.find(components, changes)
  outputs affected_out(affected)

  outputs "\nTransitively affected components"
  all_affected = TransitiveAffectedComponentFinder.new.find(affected)
  outputs affected_out(all_affected)

  outputs "\nTest scripts to run"
  outputs all_in_need_of_running = TestsToRunSelector.new(@test_runner).list(all_affected), true
end