Class: Zeus::M::TestMethod

Inherits:
Struct
  • Object
show all
Defined in:
lib/zeus/m/test_method.rb

Overview

Simple data structure for what a test method contains.

Too lazy to make a class for this when it’s really just a bag of data without any behavior.

Includes the name of this method, what line on the file it begins on, and where it ends.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#end_lineObject

Returns the value of attribute end_line

Returns:

  • (Object)

    the current value of end_line



10
11
12
# File 'lib/zeus/m/test_method.rb', line 10

def end_line
  @end_line
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



10
11
12
# File 'lib/zeus/m/test_method.rb', line 10

def name
  @name
end

#start_lineObject

Returns the value of attribute start_line

Returns:

  • (Object)

    the current value of start_line



10
11
12
# File 'lib/zeus/m/test_method.rb', line 10

def start_line
  @start_line
end

Class Method Details

.create(suite_class, test_method, find_locations = true) ⇒ Object

Set up a new test method for this test suite class



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zeus/m/test_method.rb', line 12

def self.create(suite_class, test_method, find_locations = true)
  # Hopefully it's been defined as an instance method, so we'll need to
  # look up the ruby Method instance for it
  method = suite_class.instance_method(test_method)

  if find_locations
    # Ruby can find the starting line for us, so pull that out of the array
    start_line = method.source_location.last

    # Ruby can't find the end line however, and I'm too lazy to write
    # a parser. Instead, `method_source` adds `Method#source` so we can
    # deduce this ourselves.
    #
    # The end line should be the number of line breaks in the method source,
    # added to the starting line and subtracted by one.
    end_line = method.source.split("\n").size + start_line - 1
  end

  # Shove the given attributes into a new databag
  new(test_method, start_line, end_line)
end