lib/CLIntegracon/file_tree_spec.rb in clintegracon-0.7.0 vs lib/CLIntegracon/file_tree_spec.rb in clintegracon-0.8.0

- old
+ new

@@ -43,10 +43,22 @@ # The concrete temp directory for this spec def temp_path context.temp_path + spec_folder end + # @return [Pathname] + # The concrete temp raw directory for this spec + def temp_raw_path + temp_path + 'raw' + end + + # @return [Pathname] + # The concrete transformed temp directory for this spec + def temp_transformed_path + temp_path + 'transformed' + end + # @return [String|NilClass] # The name of an optional #base_spec. attr_reader :base_spec_name # Return whether this spec is based on another spec. @@ -92,11 +104,11 @@ def run(&block) prepare! copy_files! - Dir.chdir(temp_path) do + Dir.chdir(temp_transformed_path) do block.call self end end # Compares the expected and produced directory by using the rules @@ -105,10 +117,13 @@ # @param [Block<(Diff)->()>] diff_block # The block, where you will likely define a test for each file to compare. # It will receive a Diff of each of the expected and produced files. # def compare(&diff_block) + # Get a copy of the outputs before any transformations are applied + FileUtils.cp_r("#{temp_transformed_path}/.", temp_raw_path) + transform_paths! glob_all(after_path).each do |relative_path| expected = after_path + relative_path @@ -162,20 +177,22 @@ def prepare! context.prepare! temp_path.rmtree if temp_path.exist? temp_path.mkdir + temp_raw_path.mkdir + temp_transformed_path.mkdir end - # Copies the before subdirectory of the given tests folder in the temporary + # Copies the before subdirectory of the given tests folder in the raw # directory. # def copy_files! - destination = temp_path + destination = temp_transformed_path if has_base? - FileUtils.cp_r("#{base_spec.after_path}/.", destination) + FileUtils.cp_r("#{base_spec.temp_raw_path}/.", destination) end begin FileUtils.cp_r("#{before_path}/.", destination) rescue Errno::ENOENT => e @@ -223,10 +240,10 @@ # # @return [Diff] # An object holding a diff # def diff_files(expected, relative_path, &block) - produced = temp_path + relative_path + produced = temp_transformed_path + relative_path Diff.new(expected, produced, relative_path, &block) end end end