Class: CIRunner::Runners::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_runner/runners/base.rb

Direct Known Subclasses

MinitestRunner, RSpec

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ci_log) ⇒ Base

Returns a new instance of Base.

Parameters:

  • ci_log (String)

    The CI log output.



31
32
33
34
35
# File 'lib/ci_runner/runners/base.rb', line 31

def initialize(ci_log)
  @ci_log = ci_log
  @failures = []
  @buffer = +""
end

Instance Attribute Details

#failuresArray<TestFailure>

Returns:



10
11
12
# File 'lib/ci_runner/runners/base.rb', line 10

def failures
  @failures
end

#gemfileString

Returns The Gemfile detected.

Returns:

  • (String)

    The Gemfile detected.



19
20
21
# File 'lib/ci_runner/runners/base.rb', line 19

def gemfile
  @gemfile
end

#ruby_versionString

Returns The ruby version detected.

Returns:

  • (String)

    The ruby version detected.



16
17
18
# File 'lib/ci_runner/runners/base.rb', line 16

def ruby_version
  @ruby_version
end

#seedSee TestFailure#seed

Returns:



13
14
15
# File 'lib/ci_runner/runners/base.rb', line 13

def seed
  @seed
end

Class Method Details

.match?(_) ⇒ Boolean

Children needs to implement this method to tell if they recognize the log output and if it can process them.

Parameters:

  • _ (String)

    The CI log output.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/ci_runner/runners/base.rb', line 26

def self.match?(_)
  raise NotImplementedError, "Subclass responsability"
end

Instance Method Details

#parse!void

This method returns an undefined value.

Parse the CI log. Iterate over each line and try to detect:

  • The Ruby version

  • The Gemfile used

  • Failures (Including their names, their class and the file path)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ci_runner/runners/base.rb', line 44

def parse!
  @ci_log.each_line do |line|
    line_no_ansi_color = line.gsub(/\e\[\d+m/, "")

    case line_no_ansi_color
    when seed_regex
      @seed = first_matching_group(Regexp.last_match)
    when ruby_detection_regex
      @ruby_version = first_matching_group(Regexp.last_match)

      @buffer << line_no_ansi_color if buffering?
    when gemfile_detection_regex
      @gemfile = first_matching_group(Regexp.last_match)
    when buffer_detection_regex
      if Configuration::Project.instance.process_on_new_match? && buffering?
        process_buffer
        @buffer.clear
      end

      @buffer << line_no_ansi_color
    else
      @buffer << line_no_ansi_color if buffering?
    end
  end

  process_buffer if buffering?
end

#reportvoid

This method returns an undefined value.

Output useful information to the user before the test starts. This can only be called after the runner finished parsing the log.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ci_runner/runners/base.rb', line 99

def report
  default_ruby = "No specific Ruby version detected. Will be using your current version #{RUBY_VERSION}"
  using_ruby = ruby_version ? ruby_version : default_ruby

  default_gemfile = "No specific Gemfile detected. Will be using the default Gemfile of your project."
  using_gemfile = gemfile ? gemfile : default_gemfile

  ::CLI::UI.puts(<<~EOM)

    - Test framework detected:    {{info:#{name}}}
    - Detected Ruby version:      {{info:#{using_ruby}}}
    - Detected Gemfile:           {{info:#{using_gemfile}}}
    - Number of failings tests:   {{info:#{failures.count}}}
  EOM
end

#start!Void

Entrypoint to start the runner process once it finishes parsing the log.

Returns:

  • (Void)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ci_runner/runners/base.rb', line 75

def start!
  if ruby_version && !ruby_path.exist?
    ::CLI::UI.puts(<<~EOM)
      {{warning:Couldn't find Ruby version #{ruby_version} on your system.}}
      {{warning:Searched in #{ruby_path}}}

      {{warning:The test run will start but will be running using your current Ruby version {{underline:#{RUBY_VERSION}}}.}}
    EOM
  end

  if gemfile && !gemfile_path.exist?
    ::CLI::UI.puts(<<~EOM)
      {{warning:Your CI run ran with the Gemfile #{gemfile}}}
      {{warning:I couldn't find this gemfile in your folder.}}

      {{warning:The test run will start but will be using the default Gemfile of your project}}
    EOM
  end
end