Class: Nicetest::SuperdiffPlugin::AssertIncludesMessage
- Inherits:
-
Object
- Object
- Nicetest::SuperdiffPlugin::AssertIncludesMessage
- Includes:
- Helpers
- Defined in:
- lib/minitest/superdiff_plugin.rb
Instance Method Summary collapse
- #basic_diff(expected, actual) ⇒ Object
-
#initialize(collection:, item:) ⇒ AssertIncludesMessage
constructor
A new instance of AssertIncludesMessage.
- #optional_diff ⇒ Object
- #to_s ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(collection:, item:) ⇒ AssertIncludesMessage
Returns a new instance of AssertIncludesMessage.
52 53 54 55 |
# File 'lib/minitest/superdiff_plugin.rb', line 52 def initialize(collection:, item:) @collection = collection @item = item end |
Instance Method Details
#basic_diff(expected, actual) ⇒ Object
92 93 94 95 |
# File 'lib/minitest/superdiff_plugin.rb', line 92 def basic_diff(expected, actual) content = SuperDiff.diff(expected, actual) "\nDiff:\n\n#{content}" end |
#optional_diff ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/minitest/superdiff_plugin.rb', line 84 def optional_diff case @collection when Array, Set collection_with_item = @collection + [@item].flatten(1) basic_diff(@collection, collection_with_item) end end |
#to_s ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/minitest/superdiff_plugin.rb', line 57 def to_s return @to_s if defined?(@to_s) content = if (diff = optional_diff) collection = inspect_styled(@collection, :expected) item = inspect_styled(@item, :actual) <<~OUTPUT.strip Expected #{collection} to include #{item}, but it did not. #{diff} OUTPUT else expected = inspect_styled(@collection, :expected, prefix: " Collection: ") actual = inspect_styled(@item, :actual, prefix: "Missing item: ") <<~OUTPUT.strip Expected collection to include item but it did not. #{expected} #{actual} OUTPUT end @to_s ||= content end |