Class: Test

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/flutter_tests/model/test_item.rb

Overview

Class that represents a single test that has been run

Instance Method Summary collapse

Constructor Details

#initialize(id, name) ⇒ Test

Returns a new instance of Test.



3
4
5
6
7
8
9
10
11
12
# File 'lib/fastlane/plugin/flutter_tests/model/test_item.rb', line 3

def initialize(id, name)
  @test_id = id
  @test_name = name
  @test_done = false
  @test_successful = ''
  @test_error = nil
  @test_stacktrace = nil
  @test_was_skipped = false
  @test_was_printed = false
end

Instance Method Details

#can_printObject



33
34
35
# File 'lib/fastlane/plugin/flutter_tests/model/test_item.rb', line 33

def can_print
  !@test_was_printed
end

#generate_messageObject

Generates a loggable message for the given test



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastlane/plugin/flutter_tests/model/test_item.rb', line 48

def generate_message
  @test_was_printed = true
  tag = @test_was_skipped ? 'skipped' : @test_successful

  default_message = "[#{tag}] #{@test_name}"
  if @test_successful != 'success'
    default_message += "\n[ERROR] -> #{@test_error}\n[STACKTRACE]\n#{@test_stacktrace}"
  end

  if %w[success error].include?(@test_successful) || @test_was_skipped
    color = if @test_was_skipped
              34 # Skipped tests are displayed in blue
            else
              # Successful tests are in green and the failed in red
              @test_successful == 'success' ? 32 : 31
            end

    "\e[#{color}m#{default_message}\e[0m"
  else
    default_message
  end
end

#get_idObject



29
30
31
# File 'lib/fastlane/plugin/flutter_tests/model/test_item.rb', line 29

def get_id
  @test_id
end

#get_nameObject



25
26
27
# File 'lib/fastlane/plugin/flutter_tests/model/test_item.rb', line 25

def get_name
  @test_name
end

#get_statusObject



37
38
39
40
41
42
43
# File 'lib/fastlane/plugin/flutter_tests/model/test_item.rb', line 37

def get_status
  if @test_was_skipped
    'skipped'
  else
    @test_successful
  end
end

#mark_as_done(success, skipped, error, stacktrace) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/fastlane/plugin/flutter_tests/model/test_item.rb', line 14

def mark_as_done(success, skipped, error, stacktrace)
  @test_done = true
  @test_successful = success
  @test_was_skipped = skipped
  @test_error = error
  unless stacktrace.nil?
    stacktrace = stacktrace.gsub(/ {2,}/, "\n")
    @test_stacktrace = stacktrace
  end
end