Class: M::TestCollection
- Inherits:
-
Object
- Object
- M::TestCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/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
-
#by_line_number(&block) ⇒ Object
Be considerate when printing out tests and pre-sort them by line number.
-
#column_size ⇒ Object
Used to line up method names in ‘#sprintf` when `m` aborts.
-
#initialize(collection = nil) ⇒ TestCollection
constructor
A new instance of TestCollection.
-
#within(lines) ⇒ Object
Slice out tests that may be within the given line.
Constructor Details
#initialize(collection = nil) ⇒ TestCollection
Returns a new instance of TestCollection.
14 15 16 |
# File 'lib/m/test_collection.rb', line 14 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
36 37 38 39 40 |
# File 'lib/m/test_collection.rb', line 36 def by_line_number &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_size ⇒ Object
Used to line up method names in ‘#sprintf` when `m` aborts
29 30 31 32 33 |
# File 'lib/m/test_collection.rb', line 29 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 |
#within(lines) ⇒ Object
Slice out tests that may be within the given line. Returns a new TestCollection with the results.
20 21 22 23 24 25 26 |
# File 'lib/m/test_collection.rb', line 20 def within lines # Into a new collection, filter only the tests that... collection = select do |test| lines.none? || lines.any? { |line| (test.start_line..test.end_line).cover?(line) } end self.class.new collection end |