super_diff 0.4.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +104 -73
  3. data/lib/super_diff.rb +20 -11
  4. data/lib/super_diff/active_record.rb +20 -24
  5. data/lib/super_diff/active_record/diff_formatters/active_record_relation.rb +3 -3
  6. data/lib/super_diff/active_record/differs/active_record_relation.rb +3 -5
  7. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
  8. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
  9. data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
  10. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
  11. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
  12. data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
  13. data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
  14. data/lib/super_diff/active_support.rb +16 -19
  15. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
  16. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
  17. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
  18. data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
  19. data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
  20. data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
  21. data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
  22. data/lib/super_diff/configuration.rb +60 -0
  23. data/lib/super_diff/diff_formatters.rb +3 -3
  24. data/lib/super_diff/diff_formatters/array.rb +3 -3
  25. data/lib/super_diff/diff_formatters/base.rb +3 -2
  26. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  27. data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
  28. data/lib/super_diff/diff_formatters/default_object.rb +6 -8
  29. data/lib/super_diff/diff_formatters/defaults.rb +10 -0
  30. data/lib/super_diff/diff_formatters/hash.rb +3 -3
  31. data/lib/super_diff/diff_formatters/main.rb +41 -0
  32. data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
  33. data/lib/super_diff/differs.rb +4 -11
  34. data/lib/super_diff/differs/array.rb +2 -11
  35. data/lib/super_diff/differs/base.rb +20 -3
  36. data/lib/super_diff/differs/custom_object.rb +2 -11
  37. data/lib/super_diff/differs/default_object.rb +2 -8
  38. data/lib/super_diff/differs/defaults.rb +12 -0
  39. data/lib/super_diff/differs/hash.rb +2 -11
  40. data/lib/super_diff/differs/main.rb +48 -0
  41. data/lib/super_diff/differs/multiline_string.rb +2 -14
  42. data/lib/super_diff/differs/time_like.rb +15 -0
  43. data/lib/super_diff/equality_matchers.rb +3 -9
  44. data/lib/super_diff/equality_matchers/array.rb +1 -7
  45. data/lib/super_diff/equality_matchers/base.rb +1 -1
  46. data/lib/super_diff/equality_matchers/default.rb +1 -7
  47. data/lib/super_diff/equality_matchers/defaults.rb +12 -0
  48. data/lib/super_diff/equality_matchers/hash.rb +1 -7
  49. data/lib/super_diff/equality_matchers/main.rb +21 -0
  50. data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
  51. data/lib/super_diff/errors.rb +16 -0
  52. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
  53. data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
  54. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
  55. data/lib/super_diff/implementation_checks.rb +19 -0
  56. data/lib/super_diff/object_inspection.rb +1 -10
  57. data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
  58. data/lib/super_diff/object_inspection/inspectors.rb +5 -1
  59. data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
  60. data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
  61. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
  62. data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
  63. data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
  64. data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
  65. data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
  66. data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
  67. data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
  68. data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
  69. data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
  70. data/lib/super_diff/operation_tree_builders.rb +18 -0
  71. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
  72. data/lib/super_diff/operation_tree_builders/base.rb +98 -0
  73. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
  74. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
  75. data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
  76. data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
  77. data/lib/super_diff/operation_tree_builders/main.rb +42 -0
  78. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
  79. data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
  80. data/lib/super_diff/operation_trees.rb +13 -0
  81. data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
  82. data/lib/super_diff/{operation_sequences → operation_trees}/base.rb +9 -1
  83. data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
  84. data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
  85. data/lib/super_diff/operation_trees/defaults.rb +5 -0
  86. data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
  87. data/lib/super_diff/operation_trees/main.rb +35 -0
  88. data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
  89. data/lib/super_diff/operations/unary_operation.rb +3 -0
  90. data/lib/super_diff/recursion_guard.rb +2 -0
  91. data/lib/super_diff/rspec.rb +45 -13
  92. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  93. data/lib/super_diff/rspec/differ.rb +2 -17
  94. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +2 -7
  95. data/lib/super_diff/rspec/differs/collection_including.rb +2 -7
  96. data/lib/super_diff/rspec/differs/hash_including.rb +2 -7
  97. data/lib/super_diff/rspec/differs/object_having_attributes.rb +2 -7
  98. data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
  99. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
  100. data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
  101. data/lib/super_diff/rspec/monkey_patches.rb +9 -5
  102. data/lib/super_diff/rspec/object_inspection.rb +0 -1
  103. data/lib/super_diff/rspec/object_inspection/inspectors.rb +16 -0
  104. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
  105. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +15 -9
  106. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +20 -10
  107. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
  108. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
  109. data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +20 -11
  110. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
  111. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
  112. data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
  113. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +5 -5
  114. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_including.rb +2 -2
  115. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/hash_including.rb +3 -11
  116. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/object_having_attributes.rb +4 -8
  117. data/lib/super_diff/version.rb +1 -1
  118. data/spec/examples.txt +5 -0
  119. data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  120. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  121. data/spec/integration/rspec/unhandled_errors_spec.rb +81 -4
  122. data/spec/support/command_runner.rb +3 -0
  123. data/spec/support/integration/helpers.rb +12 -96
  124. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
  125. data/spec/support/integration/test_programs/base.rb +120 -0
  126. data/spec/support/integration/test_programs/plain.rb +13 -0
  127. data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
  128. data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
  129. data/spec/support/models/active_record/person.rb +4 -11
  130. data/spec/support/models/active_record/shipping_address.rb +10 -14
  131. data/spec/support/object_id.rb +6 -5
  132. data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
  133. data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +157 -1
  134. data/spec/unit/object_inspection_spec.rb +77 -1
  135. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  136. data/super_diff.gemspec +4 -5
  137. metadata +77 -56
  138. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  139. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  140. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  141. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  142. data/lib/super_diff/diff_formatter.rb +0 -32
  143. data/lib/super_diff/differ.rb +0 -51
  144. data/lib/super_diff/differs/time.rb +0 -24
  145. data/lib/super_diff/equality_matcher.rb +0 -32
  146. data/lib/super_diff/no_differ_available_error.rb +0 -22
  147. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  148. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  149. data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
  150. data/lib/super_diff/object_inspection/map.rb +0 -30
  151. data/lib/super_diff/operation_sequences.rb +0 -9
  152. data/lib/super_diff/operational_sequencer.rb +0 -48
  153. data/lib/super_diff/operational_sequencers.rb +0 -17
  154. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  155. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  156. data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
  157. data/lib/super_diff/rspec/configuration.rb +0 -31
  158. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  159. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe SuperDiff::EqualityMatcher do
3
+ RSpec.describe SuperDiff::EqualityMatchers::Main do
4
4
  describe "#call" do
5
5
  context "given the same integers" do
6
6
  it "returns an empty string" do
@@ -1056,6 +1056,162 @@ RSpec.describe SuperDiff::EqualityMatcher do
1056
1056
  end
1057
1057
  end
1058
1058
 
1059
+ context "given two equal-size, one-dimensional hashes where there is a mixture of missing and extra keys in relatively the same order" do
1060
+ context "and the actual value is in relatively the same order as the expected" do
1061
+ it "preserves the order of the keys as they are defined" do
1062
+ actual_output = described_class.call(
1063
+ expected: {
1064
+ listed_count: 37_009,
1065
+ created_at: "Tue Jan 13 19:28:24 +0000 2009",
1066
+ favourites_count: 38,
1067
+ geo_enabled: false,
1068
+ verified: true,
1069
+ statuses_count: 273_860,
1070
+ media_count: 51_044,
1071
+ contributors_enabled: false,
1072
+ profile_background_color: "FFF1E0",
1073
+ profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",
1074
+ profile_background_tile: false,
1075
+ profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
1076
+ profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
1077
+ profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",
1078
+ },
1079
+ actual: {
1080
+ listed_count: 37_009,
1081
+ created_at: "Tue Jan 13 19:28:24 +0000 2009",
1082
+ favourites_count: 38,
1083
+ utc_offset: nil,
1084
+ time_zone: nil,
1085
+ statuses_count: 273_860,
1086
+ media_count: 51_044,
1087
+ contributors_enabled: false,
1088
+ is_translator: false,
1089
+ is_translation_enabled: false,
1090
+ profile_background_color: "FFF1E0",
1091
+ profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",
1092
+ profile_background_tile: false,
1093
+ profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",
1094
+ }
1095
+ )
1096
+
1097
+ expected_output = <<~STR.strip
1098
+ Differing hashes.
1099
+
1100
+ #{
1101
+ colored do
1102
+ alpha_line %(Expected: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, geo_enabled: false, verified: true, statuses_count: 273860, media_count: 51044, contributors_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
1103
+ beta_line %( Actual: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, time_zone: nil, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
1104
+ end
1105
+ }
1106
+
1107
+ Diff:
1108
+
1109
+ #{
1110
+ colored do
1111
+ plain_line %( {)
1112
+ plain_line %( listed_count: 37009,)
1113
+ plain_line %( created_at: "Tue Jan 13 19:28:24 +0000 2009",)
1114
+ plain_line %( favourites_count: 38,)
1115
+ alpha_line %(- geo_enabled: false,)
1116
+ alpha_line %(- verified: true,)
1117
+ beta_line %(+ utc_offset: nil,)
1118
+ beta_line %(+ time_zone: nil,)
1119
+ plain_line %( statuses_count: 273860,)
1120
+ plain_line %( media_count: 51044,)
1121
+ plain_line %( contributors_enabled: false,)
1122
+ beta_line %(+ is_translator: false,)
1123
+ beta_line %(+ is_translation_enabled: false,)
1124
+ plain_line %( profile_background_color: "FFF1E0",)
1125
+ plain_line %( profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",)
1126
+ plain_line %( profile_background_tile: false,)
1127
+ alpha_line %(- profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",)
1128
+ alpha_line %(- profile_image_url_https: "https://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",)
1129
+ plain_line %( profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592")
1130
+ plain_line %( })
1131
+ end
1132
+ }
1133
+ STR
1134
+
1135
+ expect(actual_output).to eq(expected_output)
1136
+ end
1137
+ end
1138
+
1139
+ context "and the actual value is in a different order than the expected" do
1140
+ it "preserves the order of the keys as they are defined" do
1141
+ actual_output = described_class.call(
1142
+ expected: {
1143
+ created_at: "Tue Jan 13 19:28:24 +0000 2009",
1144
+ favourites_count: 38,
1145
+ geo_enabled: false,
1146
+ verified: true,
1147
+ media_count: 51_044,
1148
+ statuses_count: 273_860,
1149
+ contributors_enabled: false,
1150
+ profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",
1151
+ profile_background_color: "FFF1E0",
1152
+ profile_background_tile: false,
1153
+ profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",
1154
+ listed_count: 37_009,
1155
+ profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",
1156
+ },
1157
+ actual: {
1158
+ listed_count: 37_009,
1159
+ created_at: "Tue Jan 13 19:28:24 +0000 2009",
1160
+ favourites_count: 38,
1161
+ utc_offset: nil,
1162
+ statuses_count: 273_860,
1163
+ media_count: 51_044,
1164
+ contributors_enabled: false,
1165
+ is_translator: false,
1166
+ is_translation_enabled: false,
1167
+ profile_background_color: "FFF1E0",
1168
+ profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",
1169
+ profile_background_tile: false,
1170
+ profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592",
1171
+ }
1172
+ )
1173
+
1174
+ expected_output = <<~STR.strip
1175
+ Differing hashes.
1176
+
1177
+ #{
1178
+ colored do
1179
+ alpha_line %(Expected: { created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, geo_enabled: false, verified: true, media_count: 51044, statuses_count: 273860, contributors_enabled: false, profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_color: "FFF1E0", profile_background_tile: false, profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg", listed_count: 37009, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
1180
+ beta_line %( Actual: { listed_count: 37009, created_at: "Tue Jan 13 19:28:24 +0000 2009", favourites_count: 38, utc_offset: nil, statuses_count: 273860, media_count: 51044, contributors_enabled: false, is_translator: false, is_translation_enabled: false, profile_background_color: "FFF1E0", profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png", profile_background_tile: false, profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592" })
1181
+ end
1182
+ }
1183
+
1184
+ Diff:
1185
+
1186
+ #{
1187
+ colored do
1188
+ plain_line %( {)
1189
+ plain_line %( listed_count: 37009,)
1190
+ plain_line %( created_at: "Tue Jan 13 19:28:24 +0000 2009",)
1191
+ plain_line %( favourites_count: 38,)
1192
+ alpha_line %(- geo_enabled: false,)
1193
+ alpha_line %(- verified: true,)
1194
+ beta_line %(+ utc_offset: nil,)
1195
+ plain_line %( statuses_count: 273860,)
1196
+ plain_line %( media_count: 51044,)
1197
+ plain_line %( contributors_enabled: false,)
1198
+ beta_line %(+ is_translator: false,)
1199
+ beta_line %(+ is_translation_enabled: false,)
1200
+ plain_line %( profile_background_color: "FFF1E0",)
1201
+ plain_line %( profile_background_image_url_https: "https://abs.twimg.com/images/themes/theme1/bg.png",)
1202
+ plain_line %( profile_background_tile: false,)
1203
+ alpha_line %(- profile_image_url: "http://pbs.twimg.com/profile_images/931156393108885504/EqEMtLhM_normal.jpg",)
1204
+ plain_line %( profile_banner_url: "https://pbs.twimg.com/profile_banners/18949452/1581526592")
1205
+ plain_line %( })
1206
+ end
1207
+ }
1208
+ STR
1209
+
1210
+ expect(actual_output).to eq(expected_output)
1211
+ end
1212
+ end
1213
+ end
1214
+
1059
1215
  context "given two hashes containing arrays with differing values" do
1060
1216
  it "returns a message along with the diff" do
1061
1217
  actual_output = described_class.call(
@@ -601,7 +601,7 @@ RSpec.describe SuperDiff::ObjectInspection do
601
601
  as_single_line: false,
602
602
  )
603
603
  expect(inspection).to match(
604
- /#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/
604
+ /#<SuperDiff::Test::EmptyClass:0x[a-z0-9]+>/,
605
605
  )
606
606
  end
607
607
  end
@@ -734,6 +734,82 @@ RSpec.describe SuperDiff::ObjectInspection do
734
734
  end
735
735
  end
736
736
 
737
+ context "given a kind-of-<something>" do
738
+ context "given as_single_line: true" do
739
+ it "returns a representation of the object on a single line" do
740
+ inspection = described_class.inspect(
741
+ a_kind_of(Symbol),
742
+ as_single_line: true,
743
+ )
744
+
745
+ expect(inspection).to eq(%(#<a kind of Symbol>))
746
+ end
747
+ end
748
+
749
+ context "given as_single_line: false" do
750
+ it "returns a representation of the object on a single line" do
751
+ inspection = described_class.inspect(
752
+ a_kind_of(Symbol),
753
+ as_single_line: false,
754
+ )
755
+
756
+ expect(inspection).to eq(%(#<a kind of Symbol>))
757
+ end
758
+ end
759
+ end
760
+
761
+ context "given an-instance-of-<something>" do
762
+ context "given as_single_line: true" do
763
+ it "returns a representation of the object on a single line" do
764
+ inspection = described_class.inspect(
765
+ an_instance_of(Symbol),
766
+ as_single_line: true,
767
+ )
768
+
769
+ expect(inspection).to eq(%(#<an instance of Symbol>))
770
+ end
771
+ end
772
+
773
+ context "given as_single_line: false" do
774
+ it "returns a representation of the object on a single line" do
775
+ inspection = described_class.inspect(
776
+ an_instance_of(Symbol),
777
+ as_single_line: false,
778
+ )
779
+
780
+ expect(inspection).to eq(%(#<an instance of Symbol>))
781
+ end
782
+ end
783
+ end
784
+
785
+ context "given a-value-within-<something>" do
786
+ context "given as_single_line: true" do
787
+ it "returns a representation of the object on a single line" do
788
+ inspection = described_class.inspect(
789
+ a_value_within(1).of(Time.utc(2020, 4, 9)),
790
+ as_single_line: true,
791
+ )
792
+
793
+ expect(inspection).to eq(
794
+ %(#<a value within 1 of 2020-04-09 00:00:00.000 UTC +00:00 (Time)>),
795
+ )
796
+ end
797
+ end
798
+
799
+ context "given as_single_line: false" do
800
+ it "returns a representation of the object on a single line" do
801
+ inspection = described_class.inspect(
802
+ a_value_within(1).of(Time.utc(2020, 4, 9)),
803
+ as_single_line: false,
804
+ )
805
+
806
+ expect(inspection).to eq(
807
+ %(#<a value within 1 of 2020-04-09 00:00:00.000 UTC +00:00 (Time)>),
808
+ )
809
+ end
810
+ end
811
+ end
812
+
737
813
  context "given a Double" do
738
814
  context "that is anonymous" do
739
815
  context "given as_single_line: true" do
@@ -18,6 +18,14 @@ RSpec.describe "RSpec's `raise_error` matcher" do
18
18
  end
19
19
  end
20
20
 
21
+ context "with regular expression as message (and assuming a RuntimeError)" do
22
+ it "returns the correct output" do
23
+ expect(raise_error(/hell/).description).to eq(
24
+ %|raise error #<Exception /hell/>|,
25
+ )
26
+ end
27
+ end
28
+
21
29
  context "with both an exception and a message" do
22
30
  it "returns the correct output" do
23
31
  expect(raise_error(RuntimeError, "hell").description).to eq(
@@ -25,5 +33,13 @@ RSpec.describe "RSpec's `raise_error` matcher" do
25
33
  )
26
34
  end
27
35
  end
36
+
37
+ context "with an exception and a regular expression as message" do
38
+ it "returns the correct output" do
39
+ expect(raise_error(RuntimeError, /hell/).description).to eq(
40
+ %|raise error #<RuntimeError /hell/>|,
41
+ )
42
+ end
43
+ end
28
44
  end
29
45
  end
@@ -6,11 +6,10 @@ Gem::Specification.new do |s|
6
6
  s.authors = ["Elliot Winkler"]
7
7
  s.email = ["elliot.winkler@gmail.com"]
8
8
  s.homepage = "https://github.com/mcmire/super_diff"
9
- s.summary = "Diff complex data structures in Ruby, with helpful output."
9
+ s.summary = "A better way to view differences between complex data structures in RSpec."
10
10
  s.description = <<~DESC
11
- SuperDiff is a utility that helps you diff two complex data structures in
12
- Ruby, and gives you helpful output to show you exactly how the two data
13
- structures differ.
11
+ SuperDiff is a gem that hooks into RSpec to intelligently display the
12
+ differences between two data structures of any type.
14
13
  DESC
15
14
  s.required_ruby_version = "~> 2.4"
16
15
 
@@ -18,7 +17,7 @@ Gem::Specification.new do |s|
18
17
  s.test_files = Dir["spec/**/*"]
19
18
  s.executables = Dir["exe/**/*"].map { |f| File.basename(f) }
20
19
 
21
- s.add_dependency "attr_extras"
20
+ s.add_dependency "attr_extras", '>= 6.2.4'
22
21
  s.add_dependency "diff-lcs"
23
22
  s.add_dependency "patience_diff"
24
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Winkler
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attr_extras
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 6.2.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 6.2.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: diff-lcs
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,9 +53,8 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: |
56
- SuperDiff is a utility that helps you diff two complex data structures in
57
- Ruby, and gives you helpful output to show you exactly how the two data
58
- structures differ.
56
+ SuperDiff is a gem that hooks into RSpec to intelligently display the
57
+ differences between two data structures of any type.
59
58
  email:
60
59
  - elliot.winkler@gmail.com
61
60
  executables: []
@@ -74,12 +73,11 @@ files:
74
73
  - lib/super_diff/active_record/object_inspection/inspectors.rb
75
74
  - lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb
76
75
  - lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb
77
- - lib/super_diff/active_record/object_inspection/map_extension.rb
78
- - lib/super_diff/active_record/operation_sequences.rb
79
- - lib/super_diff/active_record/operation_sequences/active_record_relation.rb
80
- - lib/super_diff/active_record/operational_sequencers.rb
81
- - lib/super_diff/active_record/operational_sequencers/active_record_model.rb
82
- - lib/super_diff/active_record/operational_sequencers/active_record_relation.rb
76
+ - lib/super_diff/active_record/operation_tree_builders.rb
77
+ - lib/super_diff/active_record/operation_tree_builders/active_record_model.rb
78
+ - lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb
79
+ - lib/super_diff/active_record/operation_trees.rb
80
+ - lib/super_diff/active_record/operation_trees/active_record_relation.rb
83
81
  - lib/super_diff/active_support.rb
84
82
  - lib/super_diff/active_support/diff_formatters.rb
85
83
  - lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb
@@ -88,12 +86,12 @@ files:
88
86
  - lib/super_diff/active_support/object_inspection.rb
89
87
  - lib/super_diff/active_support/object_inspection/inspectors.rb
90
88
  - lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb
91
- - lib/super_diff/active_support/object_inspection/map_extension.rb
92
- - lib/super_diff/active_support/operation_sequences.rb
93
- - lib/super_diff/active_support/operation_sequences/hash_with_indifferent_access.rb
94
- - lib/super_diff/active_support/operational_sequencers.rb
95
- - lib/super_diff/active_support/operational_sequencers/hash_with_indifferent_access.rb
89
+ - lib/super_diff/active_support/operation_tree_builders.rb
90
+ - lib/super_diff/active_support/operation_tree_builders/hash_with_indifferent_access.rb
91
+ - lib/super_diff/active_support/operation_trees.rb
92
+ - lib/super_diff/active_support/operation_trees/hash_with_indifferent_access.rb
96
93
  - lib/super_diff/colorized_document_extensions.rb
94
+ - lib/super_diff/configuration.rb
97
95
  - lib/super_diff/csi.rb
98
96
  - lib/super_diff/csi/bold_sequence.rb
99
97
  - lib/super_diff/csi/color.rb
@@ -105,49 +103,56 @@ files:
105
103
  - lib/super_diff/csi/reset_sequence.rb
106
104
  - lib/super_diff/csi/twenty_four_bit_color.rb
107
105
  - lib/super_diff/csi/uncolorized_document.rb
108
- - lib/super_diff/diff_formatter.rb
109
106
  - lib/super_diff/diff_formatters.rb
110
107
  - lib/super_diff/diff_formatters/array.rb
111
108
  - lib/super_diff/diff_formatters/base.rb
112
109
  - lib/super_diff/diff_formatters/collection.rb
113
110
  - lib/super_diff/diff_formatters/custom_object.rb
114
111
  - lib/super_diff/diff_formatters/default_object.rb
112
+ - lib/super_diff/diff_formatters/defaults.rb
115
113
  - lib/super_diff/diff_formatters/hash.rb
114
+ - lib/super_diff/diff_formatters/main.rb
116
115
  - lib/super_diff/diff_formatters/multiline_string.rb
117
- - lib/super_diff/differ.rb
118
116
  - lib/super_diff/differs.rb
119
117
  - lib/super_diff/differs/array.rb
120
118
  - lib/super_diff/differs/base.rb
121
119
  - lib/super_diff/differs/custom_object.rb
122
120
  - lib/super_diff/differs/default_object.rb
121
+ - lib/super_diff/differs/defaults.rb
123
122
  - lib/super_diff/differs/empty.rb
124
123
  - lib/super_diff/differs/hash.rb
124
+ - lib/super_diff/differs/main.rb
125
125
  - lib/super_diff/differs/multiline_string.rb
126
- - lib/super_diff/differs/time.rb
127
- - lib/super_diff/equality_matcher.rb
126
+ - lib/super_diff/differs/time_like.rb
128
127
  - lib/super_diff/equality_matchers.rb
129
128
  - lib/super_diff/equality_matchers/array.rb
130
129
  - lib/super_diff/equality_matchers/base.rb
131
130
  - lib/super_diff/equality_matchers/default.rb
131
+ - lib/super_diff/equality_matchers/defaults.rb
132
132
  - lib/super_diff/equality_matchers/hash.rb
133
+ - lib/super_diff/equality_matchers/main.rb
133
134
  - lib/super_diff/equality_matchers/multiline_string.rb
134
135
  - lib/super_diff/equality_matchers/primitive.rb
135
136
  - lib/super_diff/equality_matchers/singleline_string.rb
137
+ - lib/super_diff/errors.rb
138
+ - lib/super_diff/errors/no_diff_formatter_available_error.rb
139
+ - lib/super_diff/errors/no_differ_available_error.rb
140
+ - lib/super_diff/errors/no_operational_sequencer_available_error.rb
136
141
  - lib/super_diff/helpers.rb
137
- - lib/super_diff/no_differ_available_error.rb
138
- - lib/super_diff/no_operational_sequencer_available_error.rb
142
+ - lib/super_diff/implementation_checks.rb
139
143
  - lib/super_diff/object_inspection.rb
140
144
  - lib/super_diff/object_inspection/inspection_tree.rb
141
- - lib/super_diff/object_inspection/inspector.rb
142
145
  - lib/super_diff/object_inspection/inspectors.rb
143
146
  - lib/super_diff/object_inspection/inspectors/array.rb
147
+ - lib/super_diff/object_inspection/inspectors/base.rb
144
148
  - lib/super_diff/object_inspection/inspectors/custom_object.rb
145
149
  - lib/super_diff/object_inspection/inspectors/default_object.rb
150
+ - lib/super_diff/object_inspection/inspectors/defaults.rb
146
151
  - lib/super_diff/object_inspection/inspectors/hash.rb
152
+ - lib/super_diff/object_inspection/inspectors/main.rb
147
153
  - lib/super_diff/object_inspection/inspectors/primitive.rb
148
154
  - lib/super_diff/object_inspection/inspectors/string.rb
149
- - lib/super_diff/object_inspection/inspectors/time.rb
150
- - lib/super_diff/object_inspection/map.rb
155
+ - lib/super_diff/object_inspection/inspectors/time_like.rb
151
156
  - lib/super_diff/object_inspection/nodes.rb
152
157
  - lib/super_diff/object_inspection/nodes/base.rb
153
158
  - lib/super_diff/object_inspection/nodes/break.rb
@@ -158,21 +163,25 @@ files:
158
163
  - lib/super_diff/object_inspection/nodes/when_multiline.rb
159
164
  - lib/super_diff/object_inspection/nodes/when_non_empty.rb
160
165
  - lib/super_diff/object_inspection/nodes/when_singleline.rb
161
- - lib/super_diff/operation_sequences.rb
162
- - lib/super_diff/operation_sequences/array.rb
163
- - lib/super_diff/operation_sequences/base.rb
164
- - lib/super_diff/operation_sequences/custom_object.rb
165
- - lib/super_diff/operation_sequences/default_object.rb
166
- - lib/super_diff/operation_sequences/hash.rb
167
- - lib/super_diff/operational_sequencer.rb
168
- - lib/super_diff/operational_sequencers.rb
169
- - lib/super_diff/operational_sequencers/array.rb
170
- - lib/super_diff/operational_sequencers/base.rb
171
- - lib/super_diff/operational_sequencers/custom_object.rb
172
- - lib/super_diff/operational_sequencers/default_object.rb
173
- - lib/super_diff/operational_sequencers/hash.rb
174
- - lib/super_diff/operational_sequencers/multiline_string.rb
175
- - lib/super_diff/operational_sequencers/time_like.rb
166
+ - lib/super_diff/operation_tree_builders.rb
167
+ - lib/super_diff/operation_tree_builders/array.rb
168
+ - lib/super_diff/operation_tree_builders/base.rb
169
+ - lib/super_diff/operation_tree_builders/custom_object.rb
170
+ - lib/super_diff/operation_tree_builders/default_object.rb
171
+ - lib/super_diff/operation_tree_builders/defaults.rb
172
+ - lib/super_diff/operation_tree_builders/hash.rb
173
+ - lib/super_diff/operation_tree_builders/main.rb
174
+ - lib/super_diff/operation_tree_builders/multiline_string.rb
175
+ - lib/super_diff/operation_tree_builders/time_like.rb
176
+ - lib/super_diff/operation_trees.rb
177
+ - lib/super_diff/operation_trees/array.rb
178
+ - lib/super_diff/operation_trees/base.rb
179
+ - lib/super_diff/operation_trees/custom_object.rb
180
+ - lib/super_diff/operation_trees/default_object.rb
181
+ - lib/super_diff/operation_trees/defaults.rb
182
+ - lib/super_diff/operation_trees/hash.rb
183
+ - lib/super_diff/operation_trees/main.rb
184
+ - lib/super_diff/operation_trees/multiline_string.rb
176
185
  - lib/super_diff/operations.rb
177
186
  - lib/super_diff/operations/binary_operation.rb
178
187
  - lib/super_diff/operations/unary_operation.rb
@@ -181,7 +190,6 @@ files:
181
190
  - lib/super_diff/rspec-rails.rb
182
191
  - lib/super_diff/rspec.rb
183
192
  - lib/super_diff/rspec/augmented_matcher.rb
184
- - lib/super_diff/rspec/configuration.rb
185
193
  - lib/super_diff/rspec/differ.rb
186
194
  - lib/super_diff/rspec/differs.rb
187
195
  - lib/super_diff/rspec/differs/collection_containing_exactly.rb
@@ -203,14 +211,18 @@ files:
203
211
  - lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb
204
212
  - lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb
205
213
  - lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb
214
+ - lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb
215
+ - lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb
206
216
  - lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb
207
- - lib/super_diff/rspec/object_inspection/map_extension.rb
208
- - lib/super_diff/rspec/operational_sequencers.rb
209
- - lib/super_diff/rspec/operational_sequencers/collection_containing_exactly.rb
210
- - lib/super_diff/rspec/operational_sequencers/collection_including.rb
211
- - lib/super_diff/rspec/operational_sequencers/hash_including.rb
212
- - lib/super_diff/rspec/operational_sequencers/object_having_attributes.rb
217
+ - lib/super_diff/rspec/object_inspection/inspectors/primitive.rb
218
+ - lib/super_diff/rspec/object_inspection/inspectors/value_within.rb
219
+ - lib/super_diff/rspec/operation_tree_builders.rb
220
+ - lib/super_diff/rspec/operation_tree_builders/collection_containing_exactly.rb
221
+ - lib/super_diff/rspec/operation_tree_builders/collection_including.rb
222
+ - lib/super_diff/rspec/operation_tree_builders/hash_including.rb
223
+ - lib/super_diff/rspec/operation_tree_builders/object_having_attributes.rb
213
224
  - lib/super_diff/version.rb
225
+ - spec/examples.txt
214
226
  - spec/integration/rails/active_record_spec.rb
215
227
  - spec/integration/rails/hash_with_indifferent_access_spec.rb
216
228
  - spec/integration/rspec/be_falsey_matcher_spec.rb
@@ -235,6 +247,10 @@ files:
235
247
  - spec/support/integration/helpers.rb
236
248
  - spec/support/integration/matchers.rb
237
249
  - spec/support/integration/matchers/produce_output_when_run_matcher.rb
250
+ - spec/support/integration/test_programs/base.rb
251
+ - spec/support/integration/test_programs/plain.rb
252
+ - spec/support/integration/test_programs/rspec_active_record.rb
253
+ - spec/support/integration/test_programs/rspec_rails.rb
238
254
  - spec/support/models/a.rb
239
255
  - spec/support/models/active_record/person.rb
240
256
  - spec/support/models/active_record/query.rb
@@ -250,7 +266,7 @@ files:
250
266
  - spec/support/ruby_versions.rb
251
267
  - spec/support/shared_examples/active_record.rb
252
268
  - spec/support/shared_examples/hash_with_indifferent_access.rb
253
- - spec/unit/equality_matcher_spec.rb
269
+ - spec/unit/equality_matchers/main_spec.rb
254
270
  - spec/unit/object_inspection_spec.rb
255
271
  - spec/unit/rspec/matchers/be_compared_to_spec.rb
256
272
  - spec/unit/rspec/matchers/be_falsey_spec.rb
@@ -271,7 +287,7 @@ files:
271
287
  homepage: https://github.com/mcmire/super_diff
272
288
  licenses: []
273
289
  metadata: {}
274
- post_install_message:
290
+ post_install_message:
275
291
  rdoc_options: []
276
292
  require_paths:
277
293
  - lib
@@ -286,14 +302,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
302
  - !ruby/object:Gem::Version
287
303
  version: '0'
288
304
  requirements: []
289
- rubygems_version: 3.0.3
290
- signing_key:
305
+ rubygems_version: 3.1.2
306
+ signing_key:
291
307
  specification_version: 4
292
- summary: Diff complex data structures in Ruby, with helpful output.
308
+ summary: A better way to view differences between complex data structures in RSpec.
293
309
  test_files:
294
310
  - spec/spec_helper.rb
311
+ - spec/unit/equality_matchers/main_spec.rb
295
312
  - spec/unit/object_inspection_spec.rb
296
- - spec/unit/equality_matcher_spec.rb
297
313
  - spec/unit/rspec/matchers/contain_exactly_spec.rb
298
314
  - spec/unit/rspec/matchers/be_predicate_spec.rb
299
315
  - spec/unit/rspec/matchers/raise_error_spec.rb
@@ -309,6 +325,7 @@ test_files:
309
325
  - spec/unit/rspec/matchers/be_falsey_spec.rb
310
326
  - spec/unit/rspec/matchers/be_truthy_spec.rb
311
327
  - spec/unit/rspec/matchers/include_spec.rb
328
+ - spec/examples.txt
312
329
  - spec/integration/rspec/be_predicate_matcher_spec.rb
313
330
  - spec/integration/rspec/be_falsey_matcher_spec.rb
314
331
  - spec/integration/rspec/be_truthy_matcher_spec.rb
@@ -328,6 +345,10 @@ test_files:
328
345
  - spec/integration/rails/active_record_spec.rb
329
346
  - spec/integration/rails/hash_with_indifferent_access_spec.rb
330
347
  - spec/support/object_id.rb
348
+ - spec/support/integration/test_programs/base.rb
349
+ - spec/support/integration/test_programs/rspec_rails.rb
350
+ - spec/support/integration/test_programs/plain.rb
351
+ - spec/support/integration/test_programs/rspec_active_record.rb
331
352
  - spec/support/integration/helpers.rb
332
353
  - spec/support/integration/matchers.rb
333
354
  - spec/support/integration/matchers/produce_output_when_run_matcher.rb