Sha256: c2ff42f159de2e7be0cf9f96c807898afa1cb2bb200d6a93fa683a1dbb4b5df0

Contents?: true

Size: 1.7 KB

Versions: 25

Compression:

Stored size: 1.7 KB

Contents

require "forwardable"

module Zeus
  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, :empty?

      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(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

      # 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

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

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
zeus-0.17.0 lib/zeus/m/test_collection.rb
zeus-0.16.0 lib/zeus/m/test_collection.rb
zeus-0.15.15.pre lib/zeus/m/test_collection.rb
zeus-0.15.14 lib/zeus/m/test_collection.rb
zeus-0.15.14.pre lib/zeus/m/test_collection.rb
zeus-0.15.13 lib/zeus/m/test_collection.rb
zeus-0.15.13.pre lib/zeus/m/test_collection.rb
zeus-0.15.12 lib/zeus/m/test_collection.rb
zeus-0.15.10 lib/zeus/m/test_collection.rb
zeus-0.15.4 lib/zeus/m/test_collection.rb
zeus-0.15.3 lib/zeus/m/test_collection.rb
zeus-0.15.2 lib/zeus/m/test_collection.rb
zeus-0.15.1 lib/zeus/m/test_collection.rb
zeus-0.15.0 lib/zeus/m/test_collection.rb
zeus-justinf-0.13.5 lib/zeus/m/test_collection.rb
zeus-0.13.4.pre2 lib/zeus/m/test_collection.rb
zeus-0.13.4.pre lib/zeus/m/test_collection.rb
zeus-0.13.3 lib/zeus/m/test_collection.rb
zeus-0.13.3.rc2 lib/zeus/m/test_collection.rb
zeus-0.13.3.rc1 lib/zeus/m/test_collection.rb