Sha256: 6857c51fcd0264a4cb0fabfcaf7316fed891d2ade9f32dac3bed8eeda87e4d17

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

require 'colored'

module CLIntegracon
  class Formatter

    # @return  [FileTreeSpec]
    #          the spec
    attr_reader :spec

    # Initialize
    #
    # @param  [FileTreeSpec] spec
    #         the spec
    #
    def initialize(spec)
      super()
      @spec = spec
    end

    # Return a description text for an expectation that a file path
    # was expected to exist, but is missing.
    #
    # @param  [Pathname] file_path
    #         the file path which was expected to exist
    #
    # @return [String]
    #
    def describe_missing_file(file_path)
      description = []
      description << "Missing file for #{spec.spec_folder}:"
      description << "  * #{file_path.to_s.red}"
      description * "\n"
    end

    # Return a description text for an expectation that certain file paths
    # were unexpected.
    #
    # @param  [Array<Pathname>] file_paths
    #
    # @return [String]
    #
    def describe_unexpected_files(file_paths)
      description = []
      description << "Unexpected files for #{spec.spec_folder}:"
      description += file_paths.map { |f| "  * #{f.to_s.green}" }
      description * "\n"
    end

    # Return a description text for an expectation that two files were
    # expected to be the same, but are not.
    #
    # @param  [Diff] diff
    #         the diff which holds the difference
    #
    # @param  [Integer] max_width
    #         the max width of the terminal to print matching separators
    #
    # @return [String]
    #
    def describe_file_diff(diff, max_width=80)
      description = []
      description << "File comparison error `#{diff.relative_path}` for #{spec.spec_folder}:"
      description << "--- DIFF ".ljust(max_width, '-')
      description += diff.map do |line|
        case line
          when /^\+/ then line.green
          when /^-/ then  line.red
          else            line
        end.gsub("\n",'')
      end
      description << "--- END ".ljust(max_width, '-')
      description << ''
      description * "\n"
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clintegracon-0.5.0 lib/CLIntegracon/formatter.rb
clintegracon-0.4.1 lib/CLIntegracon/formatter.rb