Class: GitTest::Runner

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

Overview

orchestrates everything

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, notify = Notify.new) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
14
15
16
17
# File 'lib/git_test/runner.rb', line 8

def initialize(options ={} , notify = Notify.new)
  self.options     = options
  self.notify      = notify
  self.proj        = GitTest::Proj.new(options)
  self.test        = GitTest::Test.new(options)
  self.proj_branch = proj.current_branch
  self.test_dir    = Dir.mktmpdir
  prepare_proj_for_test!
  clone_to_test!
end

Instance Attribute Details

#notifyObject

Returns the value of attribute notify.



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

def notify
  @notify
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#projObject

Returns the value of attribute proj.



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

def proj
  @proj
end

#proj_branchObject

Returns the value of attribute proj_branch.



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

def proj_branch
  @proj_branch
end

#testObject

Returns the value of attribute test.



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

def test
  @test
end

#test_dirObject

Returns the value of attribute test_dir.



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

def test_dir
  @test_dir
end

#test_projObject

Returns the value of attribute test_proj.



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

def test_proj
  @test_proj
end

#writerObject

Returns the value of attribute writer.



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

def writer
  @writer
end

Instance Method Details

#clean_test_dir!Object

cleans up the temp directory



69
70
71
# File 'lib/git_test/runner.rb', line 69

def clean_test_dir!
  FileUtils.remove_entry_secure test_dir
end

#commit_to_test_proj!Object

commits contents of test branch and pushes back to local repo



101
102
103
104
105
106
107
# File 'lib/git_test/runner.rb', line 101

def commit_to_test_proj!
  test_proj.add(full_report_path)
  result = test_proj.commit("#{proj_branch} #{report_name}")
  notify.write("Pushing back to local repo")
  test_proj.real_pull('origin', report_branch)
  test_proj.push('origin', report_branch)
end

#fetch!Object

pulls from origin on the current branch and report branch



81
82
83
84
# File 'lib/git_test/runner.rb', line 81

def fetch!
  notify.write("Fetching from origin")
  proj.fetch
end

#last_report_file_name(branch = proj_branch) ⇒ Object

gives last report file name



56
57
58
# File 'lib/git_test/runner.rb', line 56

def last_report_file_name(branch = proj_branch)
  ls_report_dir(branch).last
end

#ls_report_dir(branch = proj_branch) ⇒ Object

outputs the files in the test directory for a given branch



61
62
63
64
65
# File 'lib/git_test/runner.rb', line 61

def ls_report_dir(branch = proj_branch)
  files = proj.show(report_branch, report_path(branch)).split("\n")
  files.shift(2)
  files
end

#prepare_proj_for_test!Object



31
32
33
34
# File 'lib/git_test/runner.rb', line 31

def prepare_proj_for_test!
  proj.check_repo_status!
  proj.branch(report_branch) unless proj.is_branch? report_branch
end

#push!Object

pushes to origin on the current branch and report branch



74
75
76
77
78
# File 'lib/git_test/runner.rb', line 74

def push!
  notify.write("Pushing to origin")
  proj.push('origin', proj_branch)
  proj.push('origin', report_branch)
end

#show_report(file_name = nil, branch = proj_branch) ⇒ Object

will open the specified or last report



46
47
48
49
50
51
52
53
# File 'lib/git_test/runner.rb', line 46

def show_report(file_name = nil, branch = proj_branch)
  file_name ||= last_report_file_name(branch)
  report = proj.show(report_branch, File.join(report_path(branch), file_name))
  report_file = Tempfile.new([report_name, report_extension])
  report_file.write(report)
  `open #{report_file.path}`
  sleep 3
end

#test!Object

runs the test command provided



37
38
39
40
41
42
43
# File 'lib/git_test/runner.rb', line 37

def test!
  in_test_dir do
    notify.start("Running tests on: #{proj_branch}")
    test.run!
    notify.done("Test finished: #{test.status}", test.passed?)
  end
end

#test_exit_statusObject



23
24
25
26
27
28
29
# File 'lib/git_test/runner.rb', line 23

def test_exit_status
  if test_failed?
    return -1
  else
    return 0
  end
end

#test_failed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/git_test/runner.rb', line 19

def test_failed?
  test.failed?
end

#write_report!Object

writes the result of the test command to disk



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/git_test/runner.rb', line 87

def write_report!
  notify.critical_error("Must run `test!` before writing a report") if test.status.nil?
  in_test_dir do
    self.writer  = GitTest::Writer.new(:path   => report_path,
                                       :name   => report_name,
                                       :report => test.report )
    in_report_branch do
      writer.save!
      commit_to_test_proj!
    end
  end
end