Sha256: efe207b3f56c2f95a4999d89df509ef3b83ab728a3b70233171ab26b64770e9d
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
require "forwardable" module M ### Custom wrapper around an array of test methods # In charge of some smart querying, filtering, sorting, etc on the the # test methods class TestCollection include Enumerable extend Forwardable # This should act like an array, so forward some common methods over to the # internal collection def_delegators :@collection, :size, :<<, :each def initialize collection = nil @collection = collection || [] end # Slice out tests that may be within the given line. # Returns a new TestCollection with the results. 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 # Used to line up method names in `#sprintf` when `m` aborts 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 # Be considerate when printing out tests and pre-sort them by line number 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
m-1.6.2 | lib/m/test_collection.rb |