Class: ProbeDockProbe::TestResult

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, options = {}) ⇒ TestResult

Returns a new instance of TestResult.



5
6
7
8
9
10
11
12
13
14
15
16
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
46
47
48
49
50
# File 'lib/probe_dock_ruby/test_result.rb', line 5

def initialize project, options = {}

  if !options[:fingerprint]
    raise Error, "The :fingerprint option is required (unique identifier for the test)"
  elsif !options[:name]
    raise Error, "The :name option is required (human-friendly identifier for the test, not necessarily unique)"
  elsif !options.key?(:passed)
    raise Error, "The :passed option is required (indicates whether the test passed or not)"
  elsif !options[:duration]
    raise Error, "The :duration options is required (indicates how long it took to run the test)"
  end

  @fingerprint = options[:fingerprint]

  @name = options[:name].to_s

  annotation = Annotation.new('')

  if @name.match(Annotation::ANNOTATION_REGEXP)
    annotation.merge!(Annotation.new(@name))
    @name = Annotation.strip_annotations(@name)
  end

  options_annotation = options[:annotation]
  options_annotation = Annotation.new(options_annotation) if options_annotation.kind_of?(String)
  annotation.merge!(options_annotation) if options_annotation

  @key = options[:key] || annotation.key
  @category = options[:category] || annotation.category || project.category
  @tags = (wrap(options[:tags]) + wrap(annotation.tags) + wrap(project.tags)).compact.collect(&:to_s).uniq
  @tickets = (wrap(options[:tickets]) + wrap(annotation.tickets) + wrap(project.tickets)).compact.collect(&:to_s).uniq

  @passed = !!options[:passed]

  if !options[:active].nil?
    @active = options[:active]
  elsif !annotation.active.nil?
    @active = annotation.active
  end

  @duration = options[:duration]
  @message = options[:message]

  @data = options[:data] || {}
  @data = @data.deep_stringify_keys if @data.respond_to? :deep_stringify_keys
end

Instance Attribute Details

#activeObject (readonly)

Returns the value of attribute active.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def active
  @active
end

#categoryObject (readonly)

Returns the value of attribute category.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def category
  @category
end

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def data
  @data
end

#durationObject (readonly)

Returns the value of attribute duration.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def duration
  @duration
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def fingerprint
  @fingerprint
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def key
  @key
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def tags
  @tags
end

#ticketsObject (readonly)

Returns the value of attribute tickets.



3
4
5
# File 'lib/probe_dock_ruby/test_result.rb', line 3

def tickets
  @tickets
end

Instance Method Details

#passed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/probe_dock_ruby/test_result.rb', line 52

def passed?
  @passed
end

#to_h(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/probe_dock_ruby/test_result.rb', line 56

def to_h options = {}
  {
    'f' => @fingerprint,
    'p' => @passed,
    'd' => @duration
  }.tap do |h|
    h['k'] = @key if @key
    h['m'] = @message if @message
    h['n'] = @name.length > 255 ? "#{@name[0, 252]}..." : @name
    h['c'] = @category
    h['v'] = @active unless @active.nil?
    h['g'] = @tags
    h['t'] = @tickets
    h['a'] = @data
  end
end

#wrap(a) ⇒ Object



73
74
75
# File 'lib/probe_dock_ruby/test_result.rb', line 73

def wrap a
  a.kind_of?(Array) ? a : [ a ]
end