Sha256: 6d6cb574f589be717d09e0d5506534600c928e2f8d5ee046f0933a572d32806e

Contents?: true

Size: 992 Bytes

Versions: 1

Compression:

Stored size: 992 Bytes

Contents

module GenSpec
  module GenerationMatchers
    class ResultMatcher < GenSpec::GenerationMatchers::GenerationMatcher
      attr_reader :filename
        
      def initialize(filename, &block)
        @filename = filename
        @block = block
        super(:does_not_matter)
      end
        
      def after_replay(target)
        path = File.join(target.destination_root, filename)
        if File.exist?(path)
          matched!
          validate_block(target, path)
        end
      end
        
      def failure_message
        "Expected to generate file #{filename}"
      end
        
      def negative_failure_message
        "Expected to not generate file #{filename}"
      end
        
      private
      def validate_block(target, path)
        if @block
          if @block.arity == 2
            @block.call(File.read(path), target)
          else
            @block.call(File.read(path))
          end
        else
          true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
genspec-0.1.1 lib/genspec/generation_matchers/result_matcher.rb