Class: CLIntegracon::Formatter
- Inherits:
-
Object
- Object
- CLIntegracon::Formatter
- Defined in:
- lib/CLIntegracon/formatter.rb
Instance Attribute Summary collapse
-
#spec ⇒ FileTreeSpec
readonly
The spec.
Instance Method Summary collapse
-
#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.
-
#describe_missing_file(file_path) ⇒ String
Return a description text for an expectation that a file path was expected to exist, but is missing.
-
#describe_unexpected_files(file_paths) ⇒ String
Return a description text for an expectation that certain file paths were unexpected.
-
#initialize(spec) ⇒ Formatter
constructor
Initialize.
Constructor Details
#initialize(spec) ⇒ Formatter
Initialize
15 16 17 18 |
# File 'lib/CLIntegracon/formatter.rb', line 15 def initialize(spec) super() @spec = spec end |
Instance Attribute Details
#spec ⇒ FileTreeSpec (readonly)
Returns the spec.
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.
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.
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.
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 |