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



306
307
308
# File 'lib/super_diff/rspec/monkey_patches.rb', line 306

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

.from(expected) ⇒ Object

Add a key for different sides



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/super_diff/rspec/monkey_patches.rb', line 269

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



311
312
313
314
315
316
317
318
319
# File 'lib/super_diff/rspec/monkey_patches.rb', line 311

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

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