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:


91
92
93
94
# File 'lib/CLIntegracon/formatter.rb', line 91

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

Instance Attribute Details

#specFileTreeSpec (readonly)

Returns the spec

Returns:


84
85
86
# File 'lib/CLIntegracon/formatter.rb', line 84

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)

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# 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",'')
  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)

113
114
115
116
117
118
# 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) ⇒ String

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

Parameters:

  • file_paths (Array<Pathname>)

Returns:

  • (String)

127
128
129
130
131
132
# 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

#lazyLazyStringProxy

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

Returns:


101
102
103
# File 'lib/CLIntegracon/formatter.rb', line 101

def lazy
  LazyStringProxy.new(self)
end