super_diff 0.4.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -10
  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 +4 -2
  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/integration/rspec/have_attributes_matcher_spec.rb +354 -227
  119. data/spec/integration/rspec/include_matcher_spec.rb +2 -2
  120. data/spec/integration/rspec/match_array_matcher_spec.rb +42 -0
  121. data/spec/integration/rspec/unhandled_errors_spec.rb +68 -12
  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/unit/{equality_matcher_spec.rb → equality_matchers/main_spec.rb} +157 -1
  133. data/spec/unit/object_inspection_spec.rb +77 -1
  134. data/spec/unit/rspec/matchers/raise_error_spec.rb +16 -0
  135. data/super_diff.gemspec +2 -1
  136. metadata +74 -53
  137. data/lib/super_diff/active_record/object_inspection/map_extension.rb +0 -18
  138. data/lib/super_diff/active_record/operational_sequencers.rb +0 -14
  139. data/lib/super_diff/active_support/object_inspection/map_extension.rb +0 -15
  140. data/lib/super_diff/active_support/operational_sequencers.rb +0 -10
  141. data/lib/super_diff/diff_formatter.rb +0 -32
  142. data/lib/super_diff/differ.rb +0 -51
  143. data/lib/super_diff/differs/time.rb +0 -24
  144. data/lib/super_diff/equality_matcher.rb +0 -32
  145. data/lib/super_diff/no_differ_available_error.rb +0 -22
  146. data/lib/super_diff/no_operational_sequencer_available_error.rb +0 -20
  147. data/lib/super_diff/object_inspection/inspector.rb +0 -27
  148. data/lib/super_diff/object_inspection/inspectors/time.rb +0 -13
  149. data/lib/super_diff/object_inspection/map.rb +0 -30
  150. data/lib/super_diff/operation_sequences.rb +0 -9
  151. data/lib/super_diff/operational_sequencer.rb +0 -48
  152. data/lib/super_diff/operational_sequencers.rb +0 -17
  153. data/lib/super_diff/operational_sequencers/base.rb +0 -89
  154. data/lib/super_diff/operational_sequencers/hash.rb +0 -85
  155. data/lib/super_diff/operational_sequencers/time_like.rb +0 -30
  156. data/lib/super_diff/rspec/configuration.rb +0 -31
  157. data/lib/super_diff/rspec/object_inspection/map_extension.rb +0 -23
  158. data/lib/super_diff/rspec/operational_sequencers.rb +0 -22
@@ -0,0 +1,13 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class Plain < Base
5
+ protected
6
+
7
+ def test_plan_command
8
+ "run_plain_test"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class RspecActiveRecord < Base
5
+ protected
6
+
7
+ def test_plan_prelude
8
+ "test_plan.boot_active_record"
9
+ end
10
+
11
+ def test_plan_command
12
+ "run_rspec_active_record_test"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module SuperDiff
2
+ module IntegrationTests
3
+ module TestPrograms
4
+ class RspecRails < Base
5
+ protected
6
+
7
+ def test_plan_prelude
8
+ "test_plan.boot_active_record"
9
+ end
10
+
11
+ def test_plan_command
12
+ "run_rspec_rails_test"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -9,18 +9,11 @@ module SuperDiff
9
9
  end
10
10
  end
11
11
 
12
- ActiveRecord::Base.connection.create_table(:people) do |t|
13
- t.string :name, null: false
14
- t.integer :age, null: false
15
- end
16
-
17
12
  RSpec.configure do |config|
18
13
  config.before do
19
- ActiveRecord::Base.connection.execute(
20
- "DELETE FROM people",
21
- )
22
- ActiveRecord::Base.connection.execute(
23
- "DELETE FROM sqlite_sequence WHERE name='people'",
24
- )
14
+ ActiveRecord::Base.connection.create_table(:people, force: true) do |t|
15
+ t.string :name, null: false
16
+ t.integer :age, null: false
17
+ end
25
18
  end
26
19
  end
@@ -9,21 +9,17 @@ module SuperDiff
9
9
  end
10
10
  end
11
11
 
12
- ActiveRecord::Base.connection.create_table(:shipping_addresses) do |t|
13
- t.string :line_1, null: false, default: ""
14
- t.string :line_2, null: false, default: ""
15
- t.string :city, null: false, default: ""
16
- t.string :state, null: false, default: ""
17
- t.string :zip, null: false, default: ""
18
- end
19
-
20
12
  RSpec.configure do |config|
21
13
  config.before do
22
- ActiveRecord::Base.connection.execute(
23
- "DELETE FROM shipping_addresses",
24
- )
25
- ActiveRecord::Base.connection.execute(
26
- "DELETE FROM sqlite_sequence WHERE name='shipping_addresses'",
27
- )
14
+ ActiveRecord::Base.connection.create_table(
15
+ :shipping_addresses,
16
+ force: true,
17
+ ) do |t|
18
+ t.string :line_1, null: false, default: ""
19
+ t.string :line_2, null: false, default: ""
20
+ t.string :city, null: false, default: ""
21
+ t.string :state, null: false, default: ""
22
+ t.string :zip, null: false, default: ""
23
+ end
28
24
  end
29
25
  end
@@ -1,7 +1,8 @@
1
- require_relative 'ruby_versions'
1
+ require "json"
2
+ require_relative "ruby_versions"
2
3
 
3
- if !SuperDiff::Test.jruby? && SuperDiff::Test.version_match?('>= 2.7.0')
4
- require 'objspace'
4
+ if !SuperDiff::Test.jruby? && SuperDiff::Test.version_match?(">= 2.7.0")
5
+ require "objspace"
5
6
  end
6
7
 
7
8
  module SuperDiff
@@ -11,10 +12,10 @@ module SuperDiff
11
12
  # Source: <https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyBasicObject.java>
12
13
  "0x%x" % object.hash
13
14
  end
14
- elsif version_match?('>= 2.7.0')
15
+ elsif version_match?(">= 2.7.0")
15
16
  def self.object_id_hex(object)
16
17
  # Sources: <https://bugs.ruby-lang.org/issues/15408> and <https://bugs.ruby-lang.org/issues/15626#Object-ID>
17
- address = JSON.parse(ObjectSpace.dump(object))['address']
18
+ address = JSON.parse(ObjectSpace.dump(object))["address"]
18
19
  "0x%016x" % Integer(address, 16)
19
20
  end
20
21
  else
@@ -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
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.email = ["elliot.winkler@gmail.com"]
8
8
  s.homepage = "https://github.com/mcmire/super_diff"
9
9
  s.summary = "A better way to view differences between complex data structures in RSpec."
10
+ s.license = "MIT"
10
11
  s.description = <<~DESC
11
12
  SuperDiff is a gem that hooks into RSpec to intelligently display the
12
13
  differences between two data structures of any type.
@@ -17,7 +18,7 @@ Gem::Specification.new do |s|
17
18
  s.test_files = Dir["spec/**/*"]
18
19
  s.executables = Dir["exe/**/*"].map { |f| File.basename(f) }
19
20
 
20
- s.add_dependency "attr_extras"
21
+ s.add_dependency "attr_extras", '>= 6.2.4'
21
22
  s.add_dependency "diff-lcs"
22
23
  s.add_dependency "patience_diff"
23
24
  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.1
4
+ version: 0.5.3
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-30 00:00:00.000000000 Z
11
+ date: 2020-12-21 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
@@ -73,12 +73,11 @@ files:
73
73
  - lib/super_diff/active_record/object_inspection/inspectors.rb
74
74
  - lib/super_diff/active_record/object_inspection/inspectors/active_record_model.rb
75
75
  - lib/super_diff/active_record/object_inspection/inspectors/active_record_relation.rb
76
- - lib/super_diff/active_record/object_inspection/map_extension.rb
77
- - lib/super_diff/active_record/operation_sequences.rb
78
- - lib/super_diff/active_record/operation_sequences/active_record_relation.rb
79
- - lib/super_diff/active_record/operational_sequencers.rb
80
- - lib/super_diff/active_record/operational_sequencers/active_record_model.rb
81
- - 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
82
81
  - lib/super_diff/active_support.rb
83
82
  - lib/super_diff/active_support/diff_formatters.rb
84
83
  - lib/super_diff/active_support/diff_formatters/hash_with_indifferent_access.rb
@@ -87,12 +86,12 @@ files:
87
86
  - lib/super_diff/active_support/object_inspection.rb
88
87
  - lib/super_diff/active_support/object_inspection/inspectors.rb
89
88
  - lib/super_diff/active_support/object_inspection/inspectors/hash_with_indifferent_access.rb
90
- - lib/super_diff/active_support/object_inspection/map_extension.rb
91
- - lib/super_diff/active_support/operation_sequences.rb
92
- - lib/super_diff/active_support/operation_sequences/hash_with_indifferent_access.rb
93
- - lib/super_diff/active_support/operational_sequencers.rb
94
- - 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
95
93
  - lib/super_diff/colorized_document_extensions.rb
94
+ - lib/super_diff/configuration.rb
96
95
  - lib/super_diff/csi.rb
97
96
  - lib/super_diff/csi/bold_sequence.rb
98
97
  - lib/super_diff/csi/color.rb
@@ -104,49 +103,56 @@ files:
104
103
  - lib/super_diff/csi/reset_sequence.rb
105
104
  - lib/super_diff/csi/twenty_four_bit_color.rb
106
105
  - lib/super_diff/csi/uncolorized_document.rb
107
- - lib/super_diff/diff_formatter.rb
108
106
  - lib/super_diff/diff_formatters.rb
109
107
  - lib/super_diff/diff_formatters/array.rb
110
108
  - lib/super_diff/diff_formatters/base.rb
111
109
  - lib/super_diff/diff_formatters/collection.rb
112
110
  - lib/super_diff/diff_formatters/custom_object.rb
113
111
  - lib/super_diff/diff_formatters/default_object.rb
112
+ - lib/super_diff/diff_formatters/defaults.rb
114
113
  - lib/super_diff/diff_formatters/hash.rb
114
+ - lib/super_diff/diff_formatters/main.rb
115
115
  - lib/super_diff/diff_formatters/multiline_string.rb
116
- - lib/super_diff/differ.rb
117
116
  - lib/super_diff/differs.rb
118
117
  - lib/super_diff/differs/array.rb
119
118
  - lib/super_diff/differs/base.rb
120
119
  - lib/super_diff/differs/custom_object.rb
121
120
  - lib/super_diff/differs/default_object.rb
121
+ - lib/super_diff/differs/defaults.rb
122
122
  - lib/super_diff/differs/empty.rb
123
123
  - lib/super_diff/differs/hash.rb
124
+ - lib/super_diff/differs/main.rb
124
125
  - lib/super_diff/differs/multiline_string.rb
125
- - lib/super_diff/differs/time.rb
126
- - lib/super_diff/equality_matcher.rb
126
+ - lib/super_diff/differs/time_like.rb
127
127
  - lib/super_diff/equality_matchers.rb
128
128
  - lib/super_diff/equality_matchers/array.rb
129
129
  - lib/super_diff/equality_matchers/base.rb
130
130
  - lib/super_diff/equality_matchers/default.rb
131
+ - lib/super_diff/equality_matchers/defaults.rb
131
132
  - lib/super_diff/equality_matchers/hash.rb
133
+ - lib/super_diff/equality_matchers/main.rb
132
134
  - lib/super_diff/equality_matchers/multiline_string.rb
133
135
  - lib/super_diff/equality_matchers/primitive.rb
134
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
135
141
  - lib/super_diff/helpers.rb
136
- - lib/super_diff/no_differ_available_error.rb
137
- - lib/super_diff/no_operational_sequencer_available_error.rb
142
+ - lib/super_diff/implementation_checks.rb
138
143
  - lib/super_diff/object_inspection.rb
139
144
  - lib/super_diff/object_inspection/inspection_tree.rb
140
- - lib/super_diff/object_inspection/inspector.rb
141
145
  - lib/super_diff/object_inspection/inspectors.rb
142
146
  - lib/super_diff/object_inspection/inspectors/array.rb
147
+ - lib/super_diff/object_inspection/inspectors/base.rb
143
148
  - lib/super_diff/object_inspection/inspectors/custom_object.rb
144
149
  - lib/super_diff/object_inspection/inspectors/default_object.rb
150
+ - lib/super_diff/object_inspection/inspectors/defaults.rb
145
151
  - lib/super_diff/object_inspection/inspectors/hash.rb
152
+ - lib/super_diff/object_inspection/inspectors/main.rb
146
153
  - lib/super_diff/object_inspection/inspectors/primitive.rb
147
154
  - lib/super_diff/object_inspection/inspectors/string.rb
148
- - lib/super_diff/object_inspection/inspectors/time.rb
149
- - lib/super_diff/object_inspection/map.rb
155
+ - lib/super_diff/object_inspection/inspectors/time_like.rb
150
156
  - lib/super_diff/object_inspection/nodes.rb
151
157
  - lib/super_diff/object_inspection/nodes/base.rb
152
158
  - lib/super_diff/object_inspection/nodes/break.rb
@@ -157,21 +163,25 @@ files:
157
163
  - lib/super_diff/object_inspection/nodes/when_multiline.rb
158
164
  - lib/super_diff/object_inspection/nodes/when_non_empty.rb
159
165
  - lib/super_diff/object_inspection/nodes/when_singleline.rb
160
- - lib/super_diff/operation_sequences.rb
161
- - lib/super_diff/operation_sequences/array.rb
162
- - lib/super_diff/operation_sequences/base.rb
163
- - lib/super_diff/operation_sequences/custom_object.rb
164
- - lib/super_diff/operation_sequences/default_object.rb
165
- - lib/super_diff/operation_sequences/hash.rb
166
- - lib/super_diff/operational_sequencer.rb
167
- - lib/super_diff/operational_sequencers.rb
168
- - lib/super_diff/operational_sequencers/array.rb
169
- - lib/super_diff/operational_sequencers/base.rb
170
- - lib/super_diff/operational_sequencers/custom_object.rb
171
- - lib/super_diff/operational_sequencers/default_object.rb
172
- - lib/super_diff/operational_sequencers/hash.rb
173
- - lib/super_diff/operational_sequencers/multiline_string.rb
174
- - 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
175
185
  - lib/super_diff/operations.rb
176
186
  - lib/super_diff/operations/binary_operation.rb
177
187
  - lib/super_diff/operations/unary_operation.rb
@@ -180,7 +190,6 @@ files:
180
190
  - lib/super_diff/rspec-rails.rb
181
191
  - lib/super_diff/rspec.rb
182
192
  - lib/super_diff/rspec/augmented_matcher.rb
183
- - lib/super_diff/rspec/configuration.rb
184
193
  - lib/super_diff/rspec/differ.rb
185
194
  - lib/super_diff/rspec/differs.rb
186
195
  - lib/super_diff/rspec/differs/collection_containing_exactly.rb
@@ -202,13 +211,16 @@ files:
202
211
  - lib/super_diff/rspec/object_inspection/inspectors/collection_containing_exactly.rb
203
212
  - lib/super_diff/rspec/object_inspection/inspectors/collection_including.rb
204
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
205
216
  - lib/super_diff/rspec/object_inspection/inspectors/object_having_attributes.rb
206
- - lib/super_diff/rspec/object_inspection/map_extension.rb
207
- - lib/super_diff/rspec/operational_sequencers.rb
208
- - lib/super_diff/rspec/operational_sequencers/collection_containing_exactly.rb
209
- - lib/super_diff/rspec/operational_sequencers/collection_including.rb
210
- - lib/super_diff/rspec/operational_sequencers/hash_including.rb
211
- - 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
212
224
  - lib/super_diff/version.rb
213
225
  - spec/examples.txt
214
226
  - spec/integration/rails/active_record_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
@@ -269,9 +285,10 @@ files:
269
285
  - spec/unit/rspec/matchers/respond_to_spec.rb
270
286
  - super_diff.gemspec
271
287
  homepage: https://github.com/mcmire/super_diff
272
- licenses: []
288
+ licenses:
289
+ - MIT
273
290
  metadata: {}
274
- post_install_message:
291
+ post_install_message:
275
292
  rdoc_options: []
276
293
  require_paths:
277
294
  - lib
@@ -286,14 +303,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
303
  - !ruby/object:Gem::Version
287
304
  version: '0'
288
305
  requirements: []
289
- rubygems_version: 3.0.3
290
- signing_key:
306
+ rubygems_version: 3.1.2
307
+ signing_key:
291
308
  specification_version: 4
292
309
  summary: A better way to view differences between complex data structures in RSpec.
293
310
  test_files:
294
311
  - spec/spec_helper.rb
312
+ - spec/unit/equality_matchers/main_spec.rb
295
313
  - spec/unit/object_inspection_spec.rb
296
- - spec/unit/equality_matcher_spec.rb
297
314
  - spec/unit/rspec/matchers/contain_exactly_spec.rb
298
315
  - spec/unit/rspec/matchers/be_predicate_spec.rb
299
316
  - spec/unit/rspec/matchers/raise_error_spec.rb
@@ -329,6 +346,10 @@ test_files:
329
346
  - spec/integration/rails/active_record_spec.rb
330
347
  - spec/integration/rails/hash_with_indifferent_access_spec.rb
331
348
  - spec/support/object_id.rb
349
+ - spec/support/integration/test_programs/base.rb
350
+ - spec/support/integration/test_programs/rspec_rails.rb
351
+ - spec/support/integration/test_programs/plain.rb
352
+ - spec/support/integration/test_programs/rspec_active_record.rb
332
353
  - spec/support/integration/helpers.rb
333
354
  - spec/support/integration/matchers.rb
334
355
  - spec/support/integration/matchers/produce_output_when_run_matcher.rb