Class: CLIntegracon::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/CLIntegracon/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ Formatter

Initialize

Parameters:



15
16
17
18
# File 'lib/CLIntegracon/formatter.rb', line 15

def initialize(spec)
  super()
  @spec = spec
end

Instance Attribute Details

#specFileTreeSpec (readonly)

Returns the spec.

Returns:



8
9
10
# File 'lib/CLIntegracon/formatter.rb', line 8

def spec
  @spec
end

Instance Method Details

#describe_file_diff(diff, max_width = 80) ⇒ String

Return a description text for an expectation that two files were expected to be the same, but are not.

Parameters:

  • diff (Diff)

    the diff which holds the difference

  • max_width (Integer) (defaults to: 80)

    the max width of the terminal to print matching separators

Returns:

  • (String)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/CLIntegracon/formatter.rb', line 60

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

#describe_missing_file(file_path) ⇒ String

Return a description text for an expectation that a file path was expected to exist, but is missing.

Parameters:

  • file_path (Pathname)

    the file path which was expected to exist

Returns:

  • (String)


28
29
30
31
32
33
# File 'lib/CLIntegracon/formatter.rb', line 28

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) ⇒ String

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

Parameters:

  • file_paths (Array<Pathname>)

Returns:

  • (String)


42
43
44
45
46
47
# File 'lib/CLIntegracon/formatter.rb', line 42

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