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.
-
#lazy ⇒ LazyStringProxy
Return a proxy, which returns formatted string, evaluated first if #to_s is called on this instance.
Constructor Details
#initialize(spec) ⇒ Formatter
Initialize
91 92 93 94 |
# File 'lib/CLIntegracon/formatter.rb', line 91 def initialize(spec) super() @spec = spec end |
Instance Attribute Details
#spec ⇒ FileTreeSpec (readonly)
Returns the spec.
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.
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",'').gsub("\r", '\r') 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.
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.
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 |
#lazy ⇒ LazyStringProxy
Return a proxy, which returns formatted string, evaluated first if #to_s is called on this instance.
101 102 103 |
# File 'lib/CLIntegracon/formatter.rb', line 101 def lazy LazyStringProxy.new(self) end |