Class: CLIntegracon::FileTreeSpec
- Inherits:
-
Object
- Object
- CLIntegracon::FileTreeSpec
- Defined in:
- lib/CLIntegracon/file_tree_spec.rb
Instance Attribute Summary collapse
-
#context ⇒ FileTreeSpecContext
readonly
The context, which configures path and file behaviors.
-
#spec_folder ⇒ String
readonly
The concrete spec folder.
Instance Method Summary collapse
-
#after_path ⇒ Pathname
The concrete after directory for this spec.
-
#before_path ⇒ Pathname
The concrete before directory for this spec.
-
#check_unexpected_files(&block) ⇒ Object
Compares the expected and produced directory by using the rules defined in the context for unexpected files.
-
#compare(&diff_block) ⇒ Object
Compares the expected and produced directory by using the rules defined in the context.
-
#formatter ⇒ Formatter
Return a Formatter.
-
#initialize(context, spec_folder) ⇒ FileTreeSpec
constructor
Init a spec with a given context.
-
#run(&block) ⇒ Object
Run this spec.
-
#spec_path ⇒ Pathname
The concrete spec path.
-
#temp_path ⇒ Pathname
The concrete temp directory for this spec.
Constructor Details
#initialize(context, spec_folder) ⇒ FileTreeSpec
Init a spec with a given context
48 49 50 51 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 48 def initialize(context, spec_folder) @context = context @spec_folder = spec_folder end |
Instance Attribute Details
#context ⇒ FileTreeSpecContext (readonly)
Returns The context, which configures path and file behaviors.
10 11 12 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 10 def context @context end |
#spec_folder ⇒ String (readonly)
Returns The concrete spec folder.
14 15 16 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 14 def spec_folder @spec_folder end |
Instance Method Details
#after_path ⇒ Pathname
Returns The concrete after directory for this spec.
30 31 32 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 30 def after_path spec_path + context.after_dir end |
#before_path ⇒ Pathname
Returns The concrete before directory for this spec.
24 25 26 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 24 def before_path spec_path + context.before_dir end |
#check_unexpected_files(&block) ⇒ Object
Compares the expected and produced directory by using the rules defined in the context for unexpected files.
This is separate because you probably don’t want to define an extra test case for each file, which wasn’t expected at all. So you can keep your test cases consistent.
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 107 def check_unexpected_files(&block) expected_files = glob_all after_path produced_files = glob_all unexpected_files = produced_files - expected_files # Select only files unexpected_files.reject! { |path| !path.file? } # Filter ignored paths unexpected_files.reject! { |path| special_behavior_for_path(path) == context.class.nop } block.call unexpected_files end |
#compare(&diff_block) ⇒ Object
Compares the expected and produced directory by using the rules defined in the context
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 78 def compare(&diff_block) transform_paths! glob_all(after_path).each do |relative_path| expected = after_path + relative_path next unless expected.file? block = special_behavior_for_path relative_path next if block == context.class.nop diff = diff_files(expected, relative_path) diff.preparator = block unless block.nil? diff_block.call diff end end |
#formatter ⇒ Formatter
Return a Formatter
125 126 127 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 125 def formatter @formatter ||= Formatter.new(self) end |
#run(&block) ⇒ Object
Run this spec
61 62 63 64 65 66 67 68 69 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 61 def run(&block) prepare! copy_files! Dir.chdir(temp_path) do block.call self end end |
#spec_path ⇒ Pathname
Returns The concrete spec path.
18 19 20 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 18 def spec_path context.spec_path + spec_folder end |
#temp_path ⇒ Pathname
Returns The concrete temp directory for this spec.
36 37 38 |
# File 'lib/CLIntegracon/file_tree_spec.rb', line 36 def temp_path context.temp_path + spec_folder end |