Class: RSpec::Matchers::ExpectedsForMultipleDiffs

Inherits:
Object
  • Object
show all
Defined in:
lib/super_diff/rspec/monkey_patches.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.colorizerObject



254
255
256
# File 'lib/super_diff/rspec/monkey_patches.rb', line 254

def self.colorizer
  RSpec::Core::Formatters::ConsoleCodes
end

.from(expected) ⇒ Object

Add a key for different sides



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/super_diff/rspec/monkey_patches.rb', line 217

def self.from(expected)
  return expected if self === expected

  text =
    colorizer.wrap("Diff:", SuperDiff::COLORS.fetch(:header)) +
    "\n\n" +
    colorizer.wrap(
      "┌ (Key) ──────────────────────────┐",
      SuperDiff::COLORS.fetch(:border)
    ) +
    "\n" +
    colorizer.wrap("", SuperDiff::COLORS.fetch(:border)) +
    colorizer.wrap(
      "‹-› in expected, not in actual",
      SuperDiff::COLORS.fetch(:alpha)
    ) +
    colorizer.wrap("", SuperDiff::COLORS.fetch(:border)) +
    "\n" +
    colorizer.wrap("", SuperDiff::COLORS.fetch(:border)) +
    colorizer.wrap(
      "‹+› in actual, not in expected",
      SuperDiff::COLORS.fetch(:beta)
    ) +
    colorizer.wrap("", SuperDiff::COLORS.fetch(:border)) +
    "\n" +
    colorizer.wrap("", SuperDiff::COLORS.fetch(:border)) +
    "‹ › in both expected and actual" +
    colorizer.wrap("", SuperDiff::COLORS.fetch(:border)) +
    "\n" +
    colorizer.wrap(
      "└─────────────────────────────────┘",
      SuperDiff::COLORS.fetch(:border)
    )

  new([[expected, text]])
end

Instance Method Details

#message_with_diff(message, differ, actual) ⇒ Object

Add an extra line break



259
260
261
262
263
264
265
266
267
# File 'lib/super_diff/rspec/monkey_patches.rb', line 259

def message_with_diff(message, differ, actual)
  diff = diffs(differ, actual)

  if diff.empty?
    message
  else
    "#{message.rstrip}\n\n#{diff}"
  end
end