Class: ProbeDockRSpec::TestResult

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, example, groups = [], options = {}) ⇒ TestResult

Returns a new instance of TestResult.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/probe_dock_rspec/test_result.rb', line 7

def initialize project, example, groups = [], options = {}

  @category = project.category
  @tags = project.tags
  @tickets = project.tickets

  @grouped = extract_grouped example, groups

  [ :key, :name, :category, :tags, :tickets, :data ].each do |attr|
    instance_variable_set "@#{attr}".to_sym, send("extract_#{attr}".to_sym, example, groups)
  end

  @passed = !!options[:passed]
  @duration = options[:duration]
  @message = options[:message]
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def category
  @category
end

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def data
  @data
end

#durationObject (readonly)

Returns the value of attribute duration.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def duration
  @duration
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def key
  @key
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def name
  @name
end

#tagsObject (readonly)

Returns the value of attribute tags.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def tags
  @tags
end

#ticketsObject (readonly)

Returns the value of attribute tickets.



5
6
7
# File 'lib/probe_dock_rspec/test_result.rb', line 5

def tickets
  @tickets
end

Class Method Details

.extract_grouped(example, groups = []) ⇒ Object



58
59
60
# File 'lib/probe_dock_rspec/test_result.rb', line 58

def self.extract_grouped example, groups = []
  !!groups.collect{ |g| meta(g)[:grouped] }.compact.last
end

.extract_key(example, groups = []) ⇒ Object



62
63
64
# File 'lib/probe_dock_rspec/test_result.rb', line 62

def self.extract_key example, groups = []
  (groups.collect{ |g| meta(g)[:key] } << meta(example)[:key]).compact.reject{ |k| k.strip.empty? }.last
end

.meta(holder) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/probe_dock_rspec/test_result.rb', line 66

def self.meta holder
  meta = holder.[:probe_dock] || {}
  if meta.kind_of? String
    { key: meta }
  elsif meta.kind_of? Hash
    meta
  else
    {}
  end
end

Instance Method Details

#grouped?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/probe_dock_rspec/test_result.rb', line 28

def grouped?
  @grouped
end

#passed?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/probe_dock_rspec/test_result.rb', line 24

def passed?
  @passed
end

#to_h(options = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/probe_dock_rspec/test_result.rb', line 38

def to_h options = {}
  {
    'p' => @passed,
    'd' => @duration
  }.tap do |h|

    h['k'] = @key if @key
    h['m'] = @message if @message

    cache = options[:cache]
    first = !cache || !cache.known?(self)
    stale = !first && cache.stale?(self)
    h['n'] = @name if stale or first
    h['c'] = @category if stale or (first and @category)
    h['g'] = @tags if stale or (first and !@tags.empty?)
    h['t'] = @tickets if stale or (first and !@tickets.empty?)
    h['a'] = @data if @data # FIXME: cache custom data
  end
end

#update(options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/probe_dock_rspec/test_result.rb', line 32

def update options = {}
  @passed &&= options[:passed]
  @duration += options[:duration]
  @message = [ @message, options[:message] ].select{ |m| m }.join("\n\n") if options[:message]
end