Class: CLIntegracon::FileTreeSpecContext

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

Attributes collapse

Initializer collapse

Helper collapse

DSL-like Setter 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



59
60
61
62
63
64
65
66
67
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 59

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.special_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

#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)



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

def include_hidden_files
  @include_hidden_files
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

#special_pathsHash<String,Block>

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

Returns:

  • (Hash<String,Block>)

    the special 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 special_paths
  @special_paths
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,Block>

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

Returns:

  • (Hash<String,Block>)

    the special 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

Class Method Details

.nopProc

This value is used for ignored paths

Returns:

  • (Proc)

    Does nothing



78
79
80
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 78

def self.nop
  @nop ||= Proc.new {}
end

Instance Method Details

#has_special_handling_for(*file_paths, &block) ⇒ Object

Registers a block for special handling certain files, matched with globs. Registered file paths will be excluded from default comparison by ‘diff`. Multiple special handlers can match a single file.

Parameters:

  • file_paths (String|Regexp...)

    The file path(s) of the files, which were created/changed and need special comparison

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

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



141
142
143
144
145
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 141

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

#ignores(*file_path) ⇒ Object

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

Parameters:

  • file_path (String|RegExp...)

    the file path of the files, which were changed and need special comparison



153
154
155
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 153

def ignores(*file_path)
  has_special_handling_for *file_path, &self.class.nop
end

#prepare!Object

Prepare the temporary directory and the attribute #temp_path itself.



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

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

#spec(spec_folder) ⇒ FileTreeSpec

Get a specific spec with given folder to run it

Parameters:

  • folder (String)

    The name of the folder of the tests

Returns:



176
177
178
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 176

def spec(spec_folder)
  FileTreeSpec.new(self, spec_folder)
end

#transform_produced(*file_paths, &block) ⇒ Object

Registers a block for special handling certain files, matched with globs. Multiple transformers can match a single file.

Parameters:

  • file_paths (String...)

    The file path(s) of the files, which were created/changed and need transformation

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



124
125
126
127
128
# File 'lib/CLIntegracon/file_tree_spec_context.rb', line 124

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