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.



39
40
41
42
43
44
# File 'lib/cuke_slicer/slicer.rb', line 39

def self.known_filters
  [:excluded_tags,
   :included_tags,
   :excluded_paths,
   :included_paths]
end

Instance Method Details

#slice(target, filters = {}, &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.

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cuke_slicer/slicer.rb', line 18

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


  begin
    target = File.directory?(target) ? CukeModeler::Directory.new(target) : CukeModeler::FeatureFile.new(target)
  rescue Gherkin::Lexer::LexingError
    raise(ArgumentError, "A syntax or lexing problem was encountered while trying to parse #{target}")
  end

  if target.is_a?(CukeModeler::Directory)
    sliced_tests = extract_test_cases_from_directory(target, filters, &block)
  else
    sliced_tests = extract_test_cases_from_file(target, filters, &block)
  end

  sliced_tests
end