Class: Zeus::M::TestCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/zeus/m/test_collection.rb

Overview

Custom wrapper around an array of test methods In charge of some smart querying, filtering, sorting, etc on the the test methods

Instance Method Summary collapse

Constructor Details

#initialize(collection = nil) ⇒ TestCollection

Returns a new instance of TestCollection.


15
16
17
# File 'lib/zeus/m/test_collection.rb', line 15

def initialize(collection = nil)
  @collection = collection || []
end

Instance Method Details

#by_line_number(&block) ⇒ Object

Be considerate when printing out tests and pre-sort them by line number


38
39
40
41
42
# File 'lib/zeus/m/test_collection.rb', line 38

def (&block)
  # On each member of the collection, sort by line number and yield
  # the block into the sorted collection
  sort_by(&:start_line).each(&block)
end

#column_sizeObject

Used to line up method names in `#sprintf` when `m` aborts


31
32
33
34
35
# File 'lib/zeus/m/test_collection.rb', line 31

def column_size
  # Boil down the collection of test methods to the name of the method's
  # size, then find the largest one
  @column_size ||= map { |test| test.name.to_s.size }.max
end

#contains?(test_name) ⇒ Boolean

Returns:

  • (Boolean)

44
45
46
47
48
49
# File 'lib/zeus/m/test_collection.rb', line 44

def contains? test_name
  @collection.each do |test|
    return true if test_name.match(test.name)
  end
  false
end

#within(line) ⇒ Object

Slice out tests that may be within the given line. Returns a new TestCollection with the results.


21
22
23
24
25
26
27
28
# File 'lib/zeus/m/test_collection.rb', line 21

def within(line)
  # Into a new collection, filter only the tests that...
  self.class.new(select do |test|
    # are within the given boundary for this method
    # or include everything if the line given is nil (no line)
    line.nil? || (test.start_line..test.end_line).include?(line)
  end)
end