class CLIntegracon::Formatter

Attributes

spec[R]

@return [FileTreeSpec]

the spec

Public Class Methods

new(spec) click to toggle source

Initialize

@param [FileTreeSpec] spec

the spec
Calls superclass method
# File lib/CLIntegracon/formatter.rb, line 91
def initialize(spec)
  super()
  @spec = spec
end

Public Instance Methods

describe_file_diff(diff, max_width=80) click to toggle source

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]

# File lib/CLIntegracon/formatter.rb, line 145
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",'').gsub("\r", '\r')
  end
  description << "--- END ".ljust(max_width, '-')
  description << ''
  description * "\n"
end
describe_missing_file(file_path) click to toggle source

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]

# File lib/CLIntegracon/formatter.rb, line 113
def describe_missing_file(file_path)
  description = []
  description << "Missing file for #{spec.spec_folder}:"
  description << "  * #{file_path.to_s.red}"
  description * "\n"
end
describe_unexpected_files(file_paths) click to toggle source

Return a description text for an expectation that certain file paths were unexpected.

@param [Array<Pathname>] file_paths

@return [String]

# File lib/CLIntegracon/formatter.rb, line 127
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
lazy() click to toggle source

Return a proxy, which returns formatted string, evaluated first if to_s is called on this instance.

@return [LazyStringProxy]

# File lib/CLIntegracon/formatter.rb, line 101
def lazy
  LazyStringProxy.new(self)
end