Module: Contextual::Parent

Included in:
Group, TestRunner
Defined in:
lib/contextual/parent.rb

Overview

A Parent is a Node that can have children

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenArray<Node> (readonly)

Returns:



11
12
13
# File 'lib/contextual/parent.rb', line 11

def children
  @children
end

Instance Method Details

#assign_parent(parent_options) ⇒ void

This method returns an undefined value.

Parameters:



25
26
27
28
29
30
31
32
# File 'lib/contextual/parent.rb', line 25

def assign_parent(parent_options)
  super
  @children.each do |child|
    next unless child.respond_to?(:assign_parent)

    child.assign_parent(parent_options)
  end
end

#critical_inconclusiveTestFailure

Handles when there is a error that makes it impossible to run

Returns:



127
128
129
130
131
132
133
# File 'lib/contextual/parent.rb', line 127

def critical_inconclusive
  super
  @children.each do |child|
    child.critical_inconclusive
    @test_neutral_count += 1
  end
end

#failuresInteger

Counts all failures, including children

Returns:

  • (Integer)


93
94
95
96
97
98
99
# File 'lib/contextual/parent.rb', line 93

def failures
  current_fail_count = @test_fail_count
  @children.each do |child|
    current_fail_count += child.failures if child.instance_of? Group
  end
  current_fail_count
end

#get_result(filter_settings) ⇒ TestResult

Parameters:

Returns:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/contextual/parent.rb', line 63

def get_result(filter_settings)
  super

  # This is just a stub if there's no children - do nothing
  return TestNeutral.new(@title, 'Empty - no tests') if @children.empty?

  @result = run_setup

  return @result unless @result.nil?

  @result = get_result_children(filter_settings)

  teardown_failure = run_teardown
  @result = teardown_failure unless teardown_failure.nil?

  @result
end

#neutralsInteger

Counts all neutrals, including children

Returns:

  • (Integer)


103
104
105
106
107
108
109
# File 'lib/contextual/parent.rb', line 103

def neutrals
  current_neutral_count = @test_neutral_count
  @children.each do |child|
    current_neutral_count += child.neutrals if child.instance_of? Group
  end
  current_neutral_count
end

#report_children(filter_settings) ⇒ void

This method returns an undefined value.

Parameters:



51
52
53
54
55
56
57
58
59
# File 'lib/contextual/parent.rb', line 51

def report_children(filter_settings)
  @children.each do |child|
    if @filter_applies_to_children
      child.report(filter_settings) if child.should_run_with_filter(filter_settings)
    else
      child.report(filter_settings)
    end
  end
end

#set_parent(children = []) ⇒ Object

Parameters:

  • children (Array<Node>) (defaults to: [])


14
15
16
17
18
19
20
21
# File 'lib/contextual/parent.rb', line 14

def set_parent(children = [])
  @children = children
  @test_fail_count = 0
  @test_success_count = 0
  @test_neutral_count = 0
  @filter_applies_to_children = false
  assign_children
end

#should_run_with_search_term_with_children(filter_settings) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/contextual/parent.rb', line 36

def should_run_with_search_term_with_children(filter_settings)
  # Check if the general search term applies here
  return true if should_run_with_search_term(filter_settings)

  if filter_settings.has_test_filter_term ||
     filter_settings.has_test_search_for
    should_run_filter_on_children(filter_settings)
  end

  # No applicable filter
  true
end

#successesInteger

Counts all successes, including children

Returns:

  • (Integer)


83
84
85
86
87
88
89
# File 'lib/contextual/parent.rb', line 83

def successes
  current_success_count = @test_success_count
  @children.each do |child|
    current_success_count += child.successes if child.instance_of? Group
  end
  current_success_count
end

#totalInteger

Counts all tests, including children

Returns:

  • (Integer)


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/contextual/parent.rb', line 113

def total
  test_count = 0
  @children.each do |child|
    if child.instance_of? Group
      test_count += child.total
    elsif child.instance_of?(Test) && child.ran_successfully
      test_count += 1
    end
  end
  test_count
end