Class: Ruptr::TestElement

Inherits:
Object
  • Object
show all
Defined in:
lib/ruptr/suite.rb,
lib/ruptr/runner.rb

Direct Known Subclasses

TestCase, TestGroup

Constant Summary collapse

DEFAULT_TAGS =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label = nil, identifier: label, tags: DEFAULT_TAGS, &block) ⇒ TestElement

Returns a new instance of TestElement.



7
8
9
10
11
12
13
# File 'lib/ruptr/suite.rb', line 7

def initialize(label = nil, identifier: label, tags: DEFAULT_TAGS, &block)
  @parent = nil
  @label = label
  @identifier = identifier
  @tags = tags
  @block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



15
16
17
# File 'lib/ruptr/suite.rb', line 15

def block
  @block
end

#identifierObject

Returns the value of attribute identifier.



15
16
17
# File 'lib/ruptr/suite.rb', line 15

def identifier
  @identifier
end

#labelObject

Returns the value of attribute label.



15
16
17
# File 'lib/ruptr/suite.rb', line 15

def label
  @label
end

#parentObject (readonly)

Returns the value of attribute parent.



17
18
19
# File 'lib/ruptr/suite.rb', line 17

def parent
  @parent
end

#tagsObject

Returns the value of attribute tags.



15
16
17
# File 'lib/ruptr/suite.rb', line 15

def tags
  @tags
end

Instance Method Details

#block?Boolean

Returns:

  • (Boolean)


52
# File 'lib/ruptr/suite.rb', line 52

def block? = !@block.nil?

#descriptionObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/ruptr/suite.rb', line 29

def description
  return label.nil? ? '' : label if orphan?
  @description ||= if label.nil?
                     parent.description
                   elsif parent.description.empty?
                     label
                   else
                     "#{parent.description} #{label}"
                   end
end

#each_parent_and_self {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



40
41
42
43
44
# File 'lib/ruptr/suite.rb', line 40

def each_parent_and_self(&)
  return to_enum __method__ unless block_given?
  parent.each_parent_and_self(&) unless orphan?
  yield self
end

#initialize_dup(_) ⇒ Object



54
55
56
57
# File 'lib/ruptr/suite.rb', line 54

def initialize_dup(_)
  super
  orphanize!
end

#make_result(context) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruptr/runner.rb', line 34

def make_result(context)
  status = exception = user_time = system_time = nil
  captured_stdout, captured_stderr = maybe_capture_output(context) do
    user_time, system_time = Ruptr.measure_processor_time do
      yield
    rescue *Ruptr.passthrough_exceptions
      raise
    rescue SkippedExceptionMixin => exception
      status = :skipped
    rescue Exception => exception
      status = :failed
    else
      status = :passed
    end
  end
  assertions = context.assertions_count
  ineffective_assertions = context.ineffective_assertions_count
  TestResult.new(status,
                 exception:,
                 assertions:, ineffective_assertions:,
                 user_time:, system_time:,
                 captured_stdout:, captured_stderr:)
end

#orphan?Boolean

Returns:

  • (Boolean)


19
# File 'lib/ruptr/suite.rb', line 19

def orphan? = @parent.nil?

#orphanize!Object



27
# File 'lib/ruptr/suite.rb', line 27

def orphanize! = reparent!(nil)

#path_identifiersObject



47
# File 'lib/ruptr/suite.rb', line 47

def path_identifiers = each_parent_and_self.map(&:identifier)

#path_labelsObject



46
# File 'lib/ruptr/suite.rb', line 46

def path_labels = each_parent_and_self.map(&:label)

#reparent!(new_parent) ⇒ Object



21
22
23
24
25
# File 'lib/ruptr/suite.rb', line 21

def reparent!(new_parent)
  fail "already has a parent" if new_parent && @parent
  @parent = new_parent
  @description = nil
end

#test_case?Boolean

Returns:

  • (Boolean)


49
# File 'lib/ruptr/suite.rb', line 49

def test_case? = false

#test_group?Boolean

Returns:

  • (Boolean)


50
# File 'lib/ruptr/suite.rb', line 50

def test_group? = false

#to_sObject



59
# File 'lib/ruptr/suite.rb', line 59

def to_s = "#<#{self.class}: #{description.inspect}>"