Class: MTest::Unit::TestCaseWithAnalytics

Inherits:
TestCase
  • Object
show all
Defined in:
src/ruby/core/buildkite_analytics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject

Returns the value of attribute result.



4
5
6
# File 'src/ruby/core/buildkite_analytics.rb', line 4

def result
  @result
end

Instance Method Details

#file_nameObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'src/ruby/core/buildkite_analytics.rb', line 38

def file_name
  best_guess = self.class.to_s.split('::').map(&:downcase)
  second_guess = best_guess.reject { _1 == 'test' }
  best_guess_path = "#{File.join(best_guess)}.rb"
  second_guess_path = "#{File.join(second_guess)}.rb"

  if File.exist?(best_guess_path)
    best_guess_path
  elsif File.exist?(second_guess_path)
    second_guess_path
  else
    "Could not find file for #{self.class} assumed #{best_guess}."
  end
end

#locationObject



30
31
32
33
34
35
36
# File 'src/ruby/core/buildkite_analytics.rb', line 30

def location
  return 'Could not find file' unless File.exist?(file_name)

  File.read(file_name).each_line.with_index { |line, index|
    return "#{file_name}:#{index + 1}" if line =~ /^\s*def\s*#{self.__name__}(.*)/
  }
end

#run(runner) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'src/ruby/core/buildkite_analytics.rb', line 6

def run runner
  @start_time = Time.now
  @result = ""
  begin
    @passed = nil
    self.setup
    self.run_setup_hooks
    self.__send__ self.__name__
    @result = "." unless io?
    @passed = true
  rescue Exception => e
    @passed = false
    @result = runner.puke self.class, self.__name__, e
  ensure
    begin
      self.run_teardown_hooks
      self.teardown
    rescue Exception => e
      @result = runner.puke self.class, self.__name__, e
    end
  end
  @result
end

#teardownObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'src/ruby/core/buildkite_analytics.rb', line 53

def teardown
  $buildkite_test_analytics ||= []

  $buildkite_test_analytics << {
    "scope": self.class,
    "name": self.__name__,
    "identifier": "#{self.class}##{self.__name__}",
    "location": self.location,
    "file_name": self.file_name,
    "result": (@passed ? "passed" : (@result == "S" ? "skipped" : "failed")),
    "failure_reason": (@result unless @passed),
    "history": {
      "duration": "%.6f" % [Time.now - @start_time]
    }
  }
end