Class: CLIntegracon::FileTreeSpecContext

Inherits:
Object
  • Object
show all
Defined in:
lib/CLIntegracon/file_tree_spec_context.rb

Attributes collapse

Initializer collapse

DSL-like Setter collapse

Path accessors collapse

Interaction collapse

Constructor Details

#initialize(properties = {}) ⇒ FileTreeSpecContext

“Designated” initializer

Parameters:

  • properties (Hash<Symbol,String>) (defaults to: {})

    The configuration parameter (optional): :spec_path => see self.spec_path :before_dir => see self.before_dir :after_dir => see self.after_dir :temp_path => see self.temp_path


63
64
65
66
67
68
69
70
71
72
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 63

def initialize(properties={})
  self.spec_path   = properties[:spec_path]   || '.'
  self.temp_path   = properties[:temp_path]   || 'tmp'
  self.before_dir  = properties[:before_dir]  || 'before'
  self.after_dir   = properties[:after_dir]   || 'after'
  self.transform_paths = {}
  self.preprocess_paths = {}
  self.ignore_paths = []
  self.include_hidden_files = true
end

Instance Attribute Details

#after_dirPathname

Returns The relative path from a concrete spec directory to the directory containing the expected files after the execution

Returns:

  • (Pathname)

    The relative path from a concrete spec directory to the directory containing the expected files after the execution


22
23
24
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 22

def after_dir
  @after_dir
end

#before_dirPathname

Returns The relative path from a concrete spec directory to the directory containing the input files, which will be available at execution

Returns:

  • (Pathname)

    The relative path from a concrete spec directory to the directory containing the input files, which will be available at execution


17
18
19
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 17

def before_dir
  @before_dir
end

#ignore_pathsArray<String|Regexp>

Returns the paths of files to exclude from comparison

Returns:

  • (Array<String|Regexp>)

    the paths of files to exclude from comparison


42
43
44
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 42

def ignore_paths
  @ignore_paths
end

#include_hidden_filesBool Also known as: include_hidden_files?

Returns whether to include hidden files, when searching directories (true by default)

Returns:

  • (Bool)

    whether to include hidden files, when searching directories (true by default)


46
47
48
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 46

def include_hidden_files
  @include_hidden_files
end

#preprocess_pathsHash<String|Regexp,Block>

Returns the paths of files, where an individual file diff handling is needed

Returns:

  • (Hash<String|Regexp,Block>)

    the paths of files, where an individual file diff handling is needed


38
39
40
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 38

def preprocess_paths
  @preprocess_paths
end

#spec_pathPathname

Returns The relative path to the integration specs

Returns:

  • (Pathname)

    The relative path to the integration specs


12
13
14
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 12

def spec_path
  @spec_path
end

#temp_pathPathname

Note:

*Attention*: This path will been deleted before running to ensure a clean sandbox for testing.

Returns The relative path to the directory containing the produced files after the execution. This must not be the same as the before_dir or the after_dir.

Returns:

  • (Pathname)

    The relative path to the directory containing the produced files after the execution. This must not be the same as the before_dir or the after_dir.


30
31
32
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 30

def temp_path
  @temp_path
end

#transform_pathsHash<String|Regexp,Block>

Returns the paths of files, which need to be transformed in a better comparable form

Returns:

  • (Hash<String|Regexp,Block>)

    the paths of files, which need to be transformed in a better comparable form


34
35
36
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 34

def transform_paths
  @transform_paths
end

Instance Method Details

#ignores(*file_paths) ⇒ Object

Copies the before subdirectory of the given tests folder in the temporary directory.

Parameters:

  • file_paths (String|RegExp...)

    the file path(s) of the files to exclude from comparison


147
148
149
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 147

def ignores(*file_paths)
  self.ignore_paths += file_paths
end

#ignores?(file_path) ⇒ Bool

Checks whether a given file path is to ignore.

Parameters:

  • file_path (Pathname)

    The file path to match

Returns:

  • (Bool)

185
186
187
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 185

def ignores?(file_path)
  !select_matching_file_patterns(ignore_paths, file_path).empty?
end

#prepare!Object

Prepare the temporary directory and the attribute #temp_path itself.


196
197
198
199
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 196

def prepare!
  temp_path.mkpath
  @temp_path = temp_path.realpath
end

#preprocess(*file_paths, &block) ⇒ Object

Registers a block to preprocess certain files, matched with globs or regular expressions. Registered file paths will be excluded from default comparison by `diff`. A file is preprocessed with the first matching preprocessor.

Parameters:

  • file_paths (String|Regexp...)

    The path(s)s, where an individual file diff handling is needed

  • ] (Block<(Pathname) -> (String))

    block The block, which takes each of the matched files, transforms it if needed in a better comparable form.


135
136
137
138
139
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 135

def preprocess(*file_paths, &block)
  file_paths.each do |file_path|
    self.preprocess_paths[file_path] = block
  end
end

#preprocessors_for(file_path) ⇒ Array<Block<(Pathname) -> (String)>

Returns a list of preprocessors to apply for a given file path.

Parameters:

  • file_path (Pathname)

    The file path to match

Returns:

  • (Array<Block<(Pathname) -> (String)>)

    ]


174
175
176
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 174

def preprocessors_for(file_path)
  select_matching_file_patterns(preprocess_paths, file_path).values
end

#spec(spec_folder, based_on: nil) ⇒ FileTreeSpec

Get a specific spec with given folder to run it

Parameters:

  • folder (String)

    The name of the folder of the tests

  • based_on (String)

    @see FileTreeSpec#base_spec_name

Returns:


211
212
213
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 211

def spec(spec_folder, based_on: nil)
  FileTreeSpec.new(self, spec_folder, based_on: based_on)
end

#transform_produced(*file_paths, &block) ⇒ Object

Registers a block to transform certain files, matched with globs or regular expressions. Multiple transformers can match a single file.

Parameters:

  • file_paths (String...)

    The path(s), which need to be transformed in a better comparable form

  • ] (Block<(Pathname) -> ())

    block The block, which takes each of the matched files, transforms it if needed in a better comparable form in the temporary path, so that the temporary will be compared to a given after file, or makes appropriate expects, which depend on the used test framework


117
118
119
120
121
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 117

def transform_produced(*file_paths, &block)
  file_paths.each do |file_path|
    self.transform_paths[file_path] = block
  end
end

#transformers_for(file_path) ⇒ Array<Block<(Pathname) -> ()>

Returns a list of transformers to apply for a given file path.

Parameters:

  • file_path (Pathname)

    The file path to match

Returns:

  • (Array<Block<(Pathname) -> ()>)

    ]


163
164
165
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 163

def transformers_for(file_path)
  select_matching_file_patterns(transform_paths, file_path).values
end