super_diff 0.3.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) 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 +21 -23
  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/monkey_patches.rb +9 -0
  8. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb +32 -22
  9. data/lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb +17 -7
  10. data/lib/super_diff/active_record/operation_tree_builders.rb +14 -0
  11. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_model.rb +2 -2
  12. data/lib/super_diff/active_record/{operational_sequencers → operation_tree_builders}/active_record_relation.rb +4 -4
  13. data/lib/super_diff/active_record/{operation_sequences.rb → operation_trees.rb} +2 -2
  14. data/lib/super_diff/active_record/{operation_sequences → operation_trees}/active_record_relation.rb +2 -2
  15. data/lib/super_diff/active_support.rb +16 -19
  16. data/lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb +3 -3
  17. data/lib/super_diff/active_support/differs/hash_with_indifferent_access.rb +3 -5
  18. data/lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb +17 -7
  19. data/lib/super_diff/active_support/operation_tree_builders.rb +10 -0
  20. data/lib/super_diff/active_support/{operational_sequencers → operation_tree_builders}/hash_with_indifferent_access.rb +2 -2
  21. data/lib/super_diff/active_support/{operation_sequences.rb → operation_trees.rb} +2 -2
  22. data/lib/super_diff/active_support/{operation_sequences → operation_trees}/hash_with_indifferent_access.rb +2 -2
  23. data/lib/super_diff/configuration.rb +60 -0
  24. data/lib/super_diff/csi.rb +4 -0
  25. data/lib/super_diff/diff_formatters.rb +3 -3
  26. data/lib/super_diff/diff_formatters/array.rb +3 -3
  27. data/lib/super_diff/diff_formatters/base.rb +3 -2
  28. data/lib/super_diff/diff_formatters/collection.rb +2 -2
  29. data/lib/super_diff/diff_formatters/custom_object.rb +3 -3
  30. data/lib/super_diff/diff_formatters/default_object.rb +6 -8
  31. data/lib/super_diff/diff_formatters/defaults.rb +10 -0
  32. data/lib/super_diff/diff_formatters/hash.rb +3 -3
  33. data/lib/super_diff/diff_formatters/main.rb +41 -0
  34. data/lib/super_diff/diff_formatters/multiline_string.rb +3 -3
  35. data/lib/super_diff/differs.rb +4 -11
  36. data/lib/super_diff/differs/array.rb +2 -11
  37. data/lib/super_diff/differs/base.rb +20 -3
  38. data/lib/super_diff/differs/custom_object.rb +2 -11
  39. data/lib/super_diff/differs/default_object.rb +2 -8
  40. data/lib/super_diff/differs/defaults.rb +12 -0
  41. data/lib/super_diff/differs/hash.rb +2 -11
  42. data/lib/super_diff/differs/main.rb +48 -0
  43. data/lib/super_diff/differs/multiline_string.rb +2 -14
  44. data/lib/super_diff/differs/time_like.rb +15 -0
  45. data/lib/super_diff/equality_matchers.rb +3 -9
  46. data/lib/super_diff/equality_matchers/array.rb +1 -7
  47. data/lib/super_diff/equality_matchers/base.rb +1 -1
  48. data/lib/super_diff/equality_matchers/default.rb +2 -8
  49. data/lib/super_diff/equality_matchers/defaults.rb +12 -0
  50. data/lib/super_diff/equality_matchers/hash.rb +1 -7
  51. data/lib/super_diff/equality_matchers/main.rb +21 -0
  52. data/lib/super_diff/equality_matchers/multiline_string.rb +1 -7
  53. data/lib/super_diff/errors.rb +16 -0
  54. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +21 -0
  55. data/lib/super_diff/errors/no_differ_available_error.rb +24 -0
  56. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +22 -0
  57. data/lib/super_diff/implementation_checks.rb +19 -0
  58. data/lib/super_diff/object_inspection.rb +1 -10
  59. data/lib/super_diff/object_inspection/inspection_tree.rb +6 -2
  60. data/lib/super_diff/object_inspection/inspectors.rb +5 -1
  61. data/lib/super_diff/object_inspection/inspectors/array.rb +20 -10
  62. data/lib/super_diff/object_inspection/inspectors/base.rb +36 -0
  63. data/lib/super_diff/object_inspection/inspectors/custom_object.rb +24 -14
  64. data/lib/super_diff/object_inspection/inspectors/default_object.rb +44 -30
  65. data/lib/super_diff/object_inspection/inspectors/defaults.rb +15 -0
  66. data/lib/super_diff/object_inspection/inspectors/hash.rb +20 -10
  67. data/lib/super_diff/object_inspection/inspectors/main.rb +35 -0
  68. data/lib/super_diff/object_inspection/inspectors/primitive.rb +20 -5
  69. data/lib/super_diff/object_inspection/inspectors/string.rb +15 -5
  70. data/lib/super_diff/object_inspection/inspectors/time_like.rb +23 -0
  71. data/lib/super_diff/object_inspection/nodes/inspection.rb +9 -2
  72. data/lib/super_diff/operation_tree_builders.rb +18 -0
  73. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/array.rb +38 -59
  74. data/lib/super_diff/operation_tree_builders/base.rb +98 -0
  75. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/custom_object.rb +3 -3
  76. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/default_object.rb +8 -3
  77. data/lib/super_diff/operation_tree_builders/defaults.rb +5 -0
  78. data/lib/super_diff/operation_tree_builders/hash.rb +226 -0
  79. data/lib/super_diff/operation_tree_builders/main.rb +42 -0
  80. data/lib/super_diff/{operational_sequencers → operation_tree_builders}/multiline_string.rb +3 -3
  81. data/lib/super_diff/operation_tree_builders/time_like.rb +34 -0
  82. data/lib/super_diff/operation_trees.rb +13 -0
  83. data/lib/super_diff/{operation_sequences → operation_trees}/array.rb +5 -1
  84. data/lib/super_diff/operation_trees/base.rb +31 -0
  85. data/lib/super_diff/{operation_sequences → operation_trees}/custom_object.rb +5 -1
  86. data/lib/super_diff/{operation_sequences → operation_trees}/default_object.rb +10 -8
  87. data/lib/super_diff/operation_trees/defaults.rb +5 -0
  88. data/lib/super_diff/{operation_sequences → operation_trees}/hash.rb +5 -1
  89. data/lib/super_diff/operation_trees/main.rb +35 -0
  90. data/lib/super_diff/operation_trees/multiline_string.rb +18 -0
  91. data/lib/super_diff/operations/unary_operation.rb +3 -0
  92. data/lib/super_diff/rspec.rb +54 -22
  93. data/lib/super_diff/rspec/augmented_matcher.rb +1 -1
  94. data/lib/super_diff/rspec/differ.rb +2 -17
  95. data/lib/super_diff/rspec/differs.rb +9 -3
  96. data/lib/super_diff/rspec/differs/collection_containing_exactly.rb +3 -8
  97. data/lib/super_diff/rspec/differs/collection_including.rb +18 -0
  98. data/lib/super_diff/rspec/differs/hash_including.rb +18 -0
  99. data/lib/super_diff/rspec/differs/object_having_attributes.rb +17 -0
  100. data/lib/super_diff/rspec/matcher_text_builders.rb +4 -0
  101. data/lib/super_diff/rspec/matcher_text_builders/be_predicate.rb +26 -7
  102. data/lib/super_diff/rspec/matcher_text_builders/have_predicate.rb +61 -0
  103. data/lib/super_diff/rspec/matcher_text_builders/match.rb +1 -1
  104. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +13 -1
  105. data/lib/super_diff/rspec/matcher_text_builders/respond_to.rb +1 -1
  106. data/lib/super_diff/rspec/matcher_text_template.rb +1 -1
  107. data/lib/super_diff/rspec/monkey_patches.rb +226 -115
  108. data/lib/super_diff/rspec/object_inspection.rb +0 -1
  109. data/lib/super_diff/rspec/object_inspection/inspectors.rb +22 -6
  110. data/lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb +17 -8
  111. data/lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb +28 -0
  112. data/lib/super_diff/rspec/object_inspection/inspectors/hash_including.rb +31 -0
  113. data/lib/super_diff/rspec/object_inspection/inspectors/instance_of.rb +23 -0
  114. data/lib/super_diff/rspec/object_inspection/inspectors/kind_of.rb +23 -0
  115. data/lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb +31 -0
  116. data/lib/super_diff/rspec/object_inspection/inspectors/primitive.rb +13 -0
  117. data/lib/super_diff/rspec/object_inspection/inspectors/value_within.rb +29 -0
  118. data/lib/super_diff/rspec/operation_tree_builders.rb +22 -0
  119. data/lib/super_diff/rspec/{operational_sequencers → operation_tree_builders}/collection_containing_exactly.rb +6 -6
  120. data/lib/super_diff/rspec/{operational_sequencers/partial_array.rb → operation_tree_builders/collection_including.rb} +4 -3
  121. data/lib/super_diff/rspec/operation_tree_builders/hash_including.rb +25 -0
  122. data/lib/super_diff/rspec/{operational_sequencers/partial_object.rb → operation_tree_builders/object_having_attributes.rb} +5 -11
  123. data/lib/super_diff/version.rb +1 -1
  124. data/spec/examples.txt +5 -350
  125. data/spec/integration/rails/active_record_spec.rb +1 -1
  126. data/spec/integration/rails/hash_with_indifferent_access_spec.rb +1 -1
  127. data/spec/integration/rspec/be_predicate_matcher_spec.rb +111 -59
  128. data/spec/integration/rspec/eq_matcher_spec.rb +1 -1
  129. data/spec/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  130. data/spec/integration/rspec/have_predicate_matcher_spec.rb +484 -0
  131. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  132. data/spec/integration/rspec/match_array_matcher_spec.rb +372 -0
  133. data/spec/integration/rspec/match_matcher_spec.rb +8 -8
  134. data/spec/integration/rspec/raise_error_matcher_spec.rb +605 -226
  135. data/spec/integration/rspec/third_party_matcher_spec.rb +241 -0
  136. data/spec/integration/rspec/unhandled_errors_spec.rb +110 -58
  137. data/spec/spec_helper.rb +18 -7
  138. data/spec/support/command_runner.rb +3 -0
  139. data/spec/support/integration/helpers.rb +14 -90
  140. data/spec/support/integration/matchers.rb +143 -0
  141. data/spec/support/integration/matchers/produce_output_when_run_matcher.rb +14 -29
  142. data/spec/support/integration/test_programs/base.rb +120 -0
  143. data/spec/support/integration/test_programs/plain.rb +13 -0
  144. data/spec/support/integration/test_programs/rspec_active_record.rb +17 -0
  145. data/spec/support/integration/test_programs/rspec_rails.rb +17 -0
  146. data/spec/support/models/active_record/person.rb +4 -11
  147. data/spec/support/models/active_record/query.rb +15 -0
  148. data/spec/support/models/active_record/shipping_address.rb +10 -14
  149. data/spec/support/object_id.rb +27 -0
  150. data/spec/support/ruby_versions.rb +4 -0
  151. data/spec/support/shared_examples/active_record.rb +71 -0
  152. data/spec/support/shared_examples/hash_with_indifferent_access.rb +724 -208
  153. data/spec/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +165 -9
  154. data/spec/unit/object_inspection_spec.rb +94 -18
  155. data/spec/unit/rspec/matchers/have_predicate_spec.rb +21 -0
  156. data/spec/unit/rspec/matchers/match_array_spec.rb +11 -0
  157. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  158. data/super_diff.gemspec +4 -6
  159. metadata +99 -82
  160. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  161. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  162. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  163. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  164. data/lib/super_diff/diff_formatter.rb +0 -32
  165. data/lib/super_diff/differ.rb +0 -51
  166. data/lib/super_diff/differs/time.rb +0 -24
  167. data/lib/super_diff/equality_matcher.rb +0 -32
  168. data/lib/super_diff/no_differ_available_error.rb +0 -22
  169. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  170. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  171. data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
  172. data/lib/super_diff/object_inspection/map.rb +0 -30
  173. data/lib/super_diff/operation_sequences.rb +0 -9
  174. data/lib/super_diff/operation_sequences/base.rb +0 -11
  175. data/lib/super_diff/operational_sequencer.rb +0 -48
  176. data/lib/super_diff/operational_sequencers.rb +0 -17
  177. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  178. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  179. data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
  180. data/lib/super_diff/rspec/configuration.rb +0 -31
  181. data/lib/super_diff/rspec/differs/partial_array.rb +0 -22
  182. data/lib/super_diff/rspec/differs/partial_hash.rb +0 -22
  183. data/lib/super_diff/rspec/differs/partial_object.rb +0 -22
  184. data/lib/super_diff/rspec/object_inspection/inspectors/partial_array.rb +0 -22
  185. data/lib/super_diff/rspec/object_inspection/inspectors/partial_hash.rb +0 -21
  186. data/lib/super_diff/rspec/object_inspection/inspectors/partial_object.rb +0 -21
  187. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  188. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
  189. data/lib/super_diff/rspec/operational_sequencers/partial_hash.rb +0 -32
@@ -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(
@@ -1375,13 +1531,13 @@ RSpec.describe SuperDiff::EqualityMatcher do
1375
1531
  if SuperDiff::Test.jruby?
1376
1532
  # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
1377
1533
  colored do
1378
- alpha_line %(Expected: #<SuperDiff::Test::Player:#{"0x%x" % expected.hash} @inventory=["flatline", "purple body shield"], @character="mirage", @handle="martymcfly", @ultimate=0.8, @shields=0.6, @health=0.3>)
1379
- beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%x" % actual.hash} @inventory=["wingman", "mastiff"], @character="lifeline", @handle="docbrown", @ultimate=0.8, @shields=0.6, @health=0.3>)
1534
+ alpha_line %(Expected: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(expected)} @inventory=["flatline", "purple body shield"], @character="mirage", @handle="martymcfly", @ultimate=0.8, @shields=0.6, @health=0.3>)
1535
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @inventory=["wingman", "mastiff"], @character="lifeline", @handle="docbrown", @ultimate=0.8, @shields=0.6, @health=0.3>)
1380
1536
  end
1381
1537
  else
1382
1538
  colored do
1383
- alpha_line %(Expected: #<SuperDiff::Test::Player:#{"0x%016x" % (expected.object_id * 2)} @handle="martymcfly", @character="mirage", @inventory=["flatline", "purple body shield"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1384
- beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%016x" % (actual.object_id * 2)} @handle="docbrown", @character="lifeline", @inventory=["wingman", "mastiff"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1539
+ alpha_line %(Expected: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(expected)} @handle="martymcfly", @character="mirage", @inventory=["flatline", "purple body shield"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1540
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @handle="docbrown", @character="lifeline", @inventory=["wingman", "mastiff"], @shields=0.6, @health=0.3, @ultimate=0.8>)
1385
1541
  end
1386
1542
  end
1387
1543
  }
@@ -1466,13 +1622,13 @@ RSpec.describe SuperDiff::EqualityMatcher do
1466
1622
  if SuperDiff::Test.jruby?
1467
1623
  # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
1468
1624
  colored do
1469
- alpha_line %(Expected: #<SuperDiff::Test::Item:#{"0x%x" % expected.hash} @name="camera", @quantity=3>)
1470
- beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%x" % actual.hash} @inventory=["sword"], @character="Jon", @handle="mcmire", @ultimate=true, @shields=11.4, @health=4>)
1625
+ alpha_line %(Expected: #<SuperDiff::Test::Item:#{SuperDiff::Test.object_id_hex(expected)} @name="camera", @quantity=3>)
1626
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @inventory=["sword"], @character="Jon", @handle="mcmire", @ultimate=true, @shields=11.4, @health=4>)
1471
1627
  end
1472
1628
  else
1473
1629
  colored do
1474
- alpha_line %(Expected: #<SuperDiff::Test::Item:#{"0x%016x" % (expected.object_id * 2)} @name="camera", @quantity=3>)
1475
- beta_line %( Actual: #<SuperDiff::Test::Player:#{"0x%016x" % (actual.object_id * 2)} @handle="mcmire", @character="Jon", @inventory=["sword"], @shields=11.4, @health=4, @ultimate=true>)
1630
+ alpha_line %(Expected: #<SuperDiff::Test::Item:#{SuperDiff::Test.object_id_hex(expected)} @name="camera", @quantity=3>)
1631
+ beta_line %( Actual: #<SuperDiff::Test::Player:#{SuperDiff::Test.object_id_hex(actual)} @handle="mcmire", @character="Jon", @inventory=["sword"], @shields=11.4, @health=4, @ultimate=true>)
1476
1632
  end
1477
1633
  end
1478
1634
  }
@@ -601,16 +601,16 @@ 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
608
608
  end
609
609
  end
610
610
 
611
- context "given a partial hash" do
611
+ context "given a hash-including-<something>" do
612
612
  context "given as_single_line: true" do
613
- it "returns a representation of the partial hash on a single line" do
613
+ it "returns a representation of the object on a single line" do
614
614
  inspection = described_class.inspect(
615
615
  a_hash_including(foo: "bar", baz: "qux"),
616
616
  as_single_line: true,
@@ -623,7 +623,7 @@ RSpec.describe SuperDiff::ObjectInspection do
623
623
  end
624
624
 
625
625
  context "given as_single_line: false" do
626
- it "returns a representation of the partial hash across multiple lines" do
626
+ it "returns a representation of the object across multiple lines" do
627
627
  inspection = described_class.inspect(
628
628
  a_hash_including(foo: "bar", baz: "qux"),
629
629
  as_single_line: false,
@@ -639,9 +639,9 @@ RSpec.describe SuperDiff::ObjectInspection do
639
639
  end
640
640
  end
641
641
 
642
- context "given a partial array" do
642
+ context "given a collection-including-<something>" do
643
643
  context "given as_single_line: true" do
644
- it "returns a representation of the partial hash on a single line" do
644
+ it "returns a representation of the object on a single line" do
645
645
  inspection = described_class.inspect(
646
646
  a_collection_including(1, 2, 3),
647
647
  as_single_line: true,
@@ -654,7 +654,7 @@ RSpec.describe SuperDiff::ObjectInspection do
654
654
  end
655
655
 
656
656
  context "given as_single_line: false" do
657
- it "returns a representation of the partial hash across multiple lines" do
657
+ it "returns a representation of the object across multiple lines" do
658
658
  inspection = described_class.inspect(
659
659
  a_collection_including(1, 2, 3),
660
660
  as_single_line: false,
@@ -671,9 +671,9 @@ RSpec.describe SuperDiff::ObjectInspection do
671
671
  end
672
672
  end
673
673
 
674
- context "given a partial object" do
674
+ context "given a fuzzy object" do
675
675
  context "given as_single_line: true" do
676
- it "returns a representation of the partial object on a single line" do
676
+ it "returns a representation of the object on a single line" do
677
677
  inspection = described_class.inspect(
678
678
  an_object_having_attributes(foo: "bar", baz: "qux"),
679
679
  as_single_line: true,
@@ -686,7 +686,7 @@ RSpec.describe SuperDiff::ObjectInspection do
686
686
  end
687
687
 
688
688
  context "given as_single_line: false" do
689
- it "returns a representation of the partial object across multiple lines" do
689
+ it "returns a representation of the object across multiple lines" do
690
690
  inspection = described_class.inspect(
691
691
  an_object_having_attributes(foo: "bar", baz: "qux"),
692
692
  as_single_line: false,
@@ -702,9 +702,9 @@ RSpec.describe SuperDiff::ObjectInspection do
702
702
  end
703
703
  end
704
704
 
705
- context "given a fuzzy object matching a collection containing exactly <something>" do
705
+ context "given a collection-containing-exactly-<something>" do
706
706
  context "given as_single_line: true" do
707
- it "returns a representation of the partial object on a single line" do
707
+ it "returns a representation of the object on a single line" do
708
708
  inspection = described_class.inspect(
709
709
  a_collection_containing_exactly("foo", "bar", "baz"),
710
710
  as_single_line: true,
@@ -717,7 +717,7 @@ RSpec.describe SuperDiff::ObjectInspection do
717
717
  end
718
718
 
719
719
  context "given as_single_line: false" do
720
- it "returns a representation of the partial object across multiple lines" do
720
+ it "returns a representation of the object across multiple lines" do
721
721
  inspection = described_class.inspect(
722
722
  a_collection_containing_exactly("foo", "bar", "baz"),
723
723
  as_single_line: false,
@@ -734,10 +734,86 @@ 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
740
- it "returns a representation of the partial object on a single line" do
816
+ it "returns a representation of the object on a single line" do
741
817
  inspection = described_class.inspect(
742
818
  double(foo: "bar", baz: "qux"),
743
819
  as_single_line: true,
@@ -748,7 +824,7 @@ RSpec.describe SuperDiff::ObjectInspection do
748
824
  end
749
825
 
750
826
  context "given as_single_line: false" do
751
- it "returns a representation of the partial object across multiple lines" do
827
+ it "returns a representation of the object across multiple lines" do
752
828
  inspection = described_class.inspect(
753
829
  double(foo: "bar", baz: "qux"),
754
830
  as_single_line: false,
@@ -760,7 +836,7 @@ RSpec.describe SuperDiff::ObjectInspection do
760
836
  end
761
837
  end
762
838
 
763
- context "given an ActiveRecord object" do
839
+ context "given an ActiveRecord object", active_record: true do
764
840
  context "given as_single_line: true" do
765
841
  it "returns a representation of the object on a single line" do
766
842
  inspection = described_class.inspect(
@@ -798,7 +874,7 @@ RSpec.describe SuperDiff::ObjectInspection do
798
874
  end
799
875
  end
800
876
 
801
- context "given an ActiveRecord::Relation object" do
877
+ context "given an ActiveRecord::Relation object", active_record: true do
802
878
  context "given as_single_line: true" do
803
879
  it "returns a representation of the Relation on a single line" do
804
880
  SuperDiff::Test::Models::ActiveRecord::Person.create!(
@@ -855,7 +931,7 @@ RSpec.describe SuperDiff::ObjectInspection do
855
931
  end
856
932
  end
857
933
 
858
- context "given a HashWithIndifferentAccess" do
934
+ context "given a HashWithIndifferentAccess", active_record: true do
859
935
  context "given as_single_line: true" do
860
936
  it "returns a representation of the object on a single line" do
861
937
  inspection = described_class.inspect(
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "RSpec's `have_<predicate>` matcher" do
4
+ describe "#description" do
5
+ context "given nothing" do
6
+ it "returns the correct output" do
7
+ expect(have_experience.description).to eq(
8
+ "return true for `has_experience?`",
9
+ )
10
+ end
11
+ end
12
+
13
+ context "given an argument" do
14
+ it "returns the correct output" do
15
+ expect(have_ingredients(:sugar).description).to eq(
16
+ "return true for `has_ingredients?(:sugar)`",
17
+ )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "RSpec's `match_array` matcher" do
4
+ describe "#description" do
5
+ it "returns the correct output" do
6
+ expect(match_array([:foo, :bar, :baz]).description).to eq(
7
+ "match array with :foo, :bar and :baz",
8
+ )
9
+ end
10
+ end
11
+ end