Class: CukeSlicer::Slicer

Inherits:
Object
  • Object
show all
Defined in:
lib/cuke_slicer/slicer.rb

Overview

The object responsible for slicing up a Cucumber test suite into discrete test cases.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.known_filtersObject

The filtering options that are currently supported by the slicer.



48
49
50
51
52
53
# File 'lib/cuke_slicer/slicer.rb', line 48

def self.known_filters
  %i[excluded_tags
     included_tags
     excluded_paths
     included_paths]
end

Instance Method Details

#slice(target, filters = {}, format, &block) ⇒ Object

Slices up the given location into individual test cases.

The location chosen for slicing can be a file or directory path. Optional filters can be provided in order to ignore certain kinds of test cases. See #known_filters for the available option types. Most options are either a string or regular expression, although arrays of the same can be given instead if more than one filter is desired.

A block can be provided as a filter which can allow for maximal filtering flexibility. Note, however, that this exposes the underlying modeling objects and knowledge of how they work is then required to make good use of the filter.

Finally, the test cases can be provided as a collection of file:line strings or as a collection of the object types used to represent test cases by the underlying modeling library.

Parameters:

  • target (String)

    the location that will be sliced up

  • filters (Hash) (defaults to: {})

    the filters that will be applied to the sliced test cases

  • format (Symbol)

    the type of output: :file_line or :test_object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cuke_slicer/slicer.rb', line 28

def slice(target, filters = {}, format, &block)
  validate_target(target)
  validate_filters(filters)
  validate_format(format)

  begin
    target = File.directory?(target) ? CukeModeler::Directory.new(target) : CukeModeler::FeatureFile.new(target)
  rescue => e
    raise e unless e.message =~ /lexing|parsing/i
    raise(ArgumentError, "A syntax or lexing problem was encountered while trying to parse #{target}")
  end

  if target.is_a?(CukeModeler::Directory)
    DirectoryExtractor.new.extract(target, filters, format, &block)
  else
    FileExtractor.new.extract(target, filters, format, &block)
  end
end