super_diff 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_model.rb +24 -12
  3. data/lib/super_diff/active_record/object_inspection/inspection_tree_builders/active_record_relation.rb +15 -6
  4. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/hash_with_indifferent_access.rb +23 -8
  5. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders/ordered_options.rb +46 -0
  6. data/lib/super_diff/active_support/object_inspection/inspection_tree_builders.rb +4 -0
  7. data/lib/super_diff/active_support.rb +2 -1
  8. data/lib/super_diff/differs/date_like.rb +15 -0
  9. data/lib/super_diff/differs/defaults.rb +1 -0
  10. data/lib/super_diff/differs.rb +1 -0
  11. data/lib/super_diff/errors.rb +0 -4
  12. data/lib/super_diff/object_inspection/inspection_tree.rb +25 -20
  13. data/lib/super_diff/object_inspection/inspection_tree_builders/array.rb +31 -12
  14. data/lib/super_diff/object_inspection/inspection_tree_builders/custom_object.rb +19 -9
  15. data/lib/super_diff/object_inspection/inspection_tree_builders/date_like.rb +51 -0
  16. data/lib/super_diff/object_inspection/inspection_tree_builders/default_object.rb +46 -21
  17. data/lib/super_diff/object_inspection/inspection_tree_builders/defaults.rb +1 -0
  18. data/lib/super_diff/object_inspection/inspection_tree_builders/hash.rb +39 -14
  19. data/lib/super_diff/object_inspection/inspection_tree_builders/primitive.rb +3 -5
  20. data/lib/super_diff/object_inspection/inspection_tree_builders/time_like.rb +31 -20
  21. data/lib/super_diff/object_inspection/inspection_tree_builders.rb +4 -0
  22. data/lib/super_diff/object_inspection/nodes/as_lines_when_rendering_to_lines.rb +3 -2
  23. data/lib/super_diff/operation_tree_builders/date_like.rb +15 -0
  24. data/lib/super_diff/operation_tree_builders/defaults.rb +1 -1
  25. data/lib/super_diff/operation_tree_builders.rb +1 -0
  26. data/lib/super_diff/rspec/matcher_text_builders/raise_error.rb +3 -7
  27. data/lib/super_diff/rspec/monkey_patches.rb +59 -8
  28. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_containing_exactly.rb +14 -7
  29. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/collection_including.rb +19 -13
  30. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/double.rb +30 -26
  31. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher.rb +19 -0
  32. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/hash_including.rb +19 -14
  33. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/instance_of.rb +9 -10
  34. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/kind_of.rb +9 -10
  35. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/object_having_attributes.rb +14 -7
  36. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders/value_within.rb +10 -11
  37. data/lib/super_diff/rspec/object_inspection/inspection_tree_builders.rb +4 -0
  38. data/lib/super_diff/rspec.rb +10 -9
  39. data/lib/super_diff/version.rb +1 -1
  40. data/lib/super_diff.rb +9 -0
  41. data/spec/examples.txt +543 -493
  42. data/spec/integration/rails/engines_spec.rb +8 -3
  43. data/spec/integration/rspec/contain_exactly_matcher_spec.rb +19 -19
  44. data/spec/integration/rspec/eq_matcher_spec.rb +111 -39
  45. data/spec/integration/rspec/generic_describable_matchers_spec.rb +177 -0
  46. data/spec/integration/rspec/have_attributes_matcher_spec.rb +25 -25
  47. data/spec/integration/rspec/include_matcher_spec.rb +23 -23
  48. data/spec/integration/rspec/magic_metadata_spec.rb +51 -0
  49. data/spec/integration/rspec/match_array_matcher_spec.rb +30 -30
  50. data/spec/integration/rspec/match_matcher_spec.rb +93 -93
  51. data/spec/integration/rspec/raise_error_matcher_spec.rb +813 -69
  52. data/spec/internal/log/test.log +0 -0
  53. data/spec/spec_helper.rb +3 -0
  54. data/spec/support/integration/helpers.rb +15 -10
  55. data/spec/support/integration/matchers.rb +34 -0
  56. data/spec/support/integration/test_programs/base.rb +6 -6
  57. data/spec/support/integration/test_programs/rspec_rails_engine.rb +3 -13
  58. data/spec/support/shared_examples/active_record.rb +33 -33
  59. data/spec/support/shared_examples/active_support.rb +125 -4
  60. data/spec/support/shared_examples/elided_diffs.rb +48 -48
  61. data/spec/support/shared_examples/hash_with_indifferent_access.rb +88 -88
  62. data/spec/support/shared_examples/key.rb +10 -10
  63. data/spec/unit/active_support/object_inspection_spec.rb +170 -0
  64. data/spec/unit/rspec/matchers/raise_error_spec.rb +43 -11
  65. data/spec/unit/rspec/object_inspection/rspec_matcher_spec.rb +91 -0
  66. data/spec/unit/rspec/object_inspection_spec.rb +2 -2
  67. data/spec/unit/super_diff_spec.rb +64 -0
  68. metadata +17 -4
  69. data/lib/super_diff/errors/no_diff_formatter_available_error.rb +0 -21
  70. data/lib/super_diff/errors/no_operational_sequencer_available_error.rb +0 -22
@@ -8,22 +8,21 @@ module SuperDiff
8
8
  end
9
9
 
10
10
  def call
11
- SuperDiff::ObjectInspection::InspectionTree.new do
12
- as_prelude_when_rendering_to_lines do
13
- add_text "#<a value within "
11
+ SuperDiff::ObjectInspection::InspectionTree.new do |t1|
12
+ t1.as_prelude_when_rendering_to_lines do |t2|
13
+ t2.add_text "#<a value within "
14
14
 
15
- add_inspection_of as_lines: false do |aliased_matcher|
16
- aliased_matcher.base_matcher.instance_variable_get("@delta")
17
- end
15
+ t2.add_inspection_of(
16
+ object.base_matcher.instance_variable_get("@delta"),
17
+ as_lines: false
18
+ )
18
19
 
19
- add_text " of "
20
+ t2.add_text " of "
20
21
  end
21
22
 
22
- # rubocop:disable Style/SymbolProc
23
- add_inspection_of { |aliased_matcher| aliased_matcher.expected }
24
- # rubocop:enable Style/SymbolProc
23
+ t1.add_inspection_of object.expected
25
24
 
26
- add_text ">"
25
+ t1.add_text ">"
27
26
  end
28
27
  end
29
28
  end
@@ -14,6 +14,10 @@ module SuperDiff
14
14
  :Double,
15
15
  "super_diff/rspec/object_inspection/inspection_tree_builders/double"
16
16
  )
17
+ autoload(
18
+ :GenericDescribableMatcher,
19
+ "super_diff/rspec/object_inspection/inspection_tree_builders/generic_describable_matcher"
20
+ )
17
21
  autoload(
18
22
  :HashIncluding,
19
23
  "super_diff/rspec/object_inspection/inspection_tree_builders/hash_including"
@@ -20,7 +20,7 @@ module SuperDiff
20
20
  end
21
21
 
22
22
  def self.a_hash_including_something?(value)
23
- fuzzy_object?(value) && value.respond_to?(:expecteds) &&
23
+ aliased_matcher?(value) && value.respond_to?(:expecteds) &&
24
24
  value.expecteds.one? && value.expecteds.first.is_a?(::Hash)
25
25
  end
26
26
 
@@ -31,7 +31,7 @@ module SuperDiff
31
31
  end
32
32
 
33
33
  def self.a_collection_including_something?(value)
34
- fuzzy_object?(value) && value.respond_to?(:expecteds) &&
34
+ aliased_matcher?(value) && value.respond_to?(:expecteds) &&
35
35
  !(value.expecteds.one? && value.expecteds.first.is_a?(::Hash))
36
36
  end
37
37
 
@@ -40,17 +40,17 @@ module SuperDiff
40
40
  end
41
41
 
42
42
  def self.an_object_having_some_attributes?(value)
43
- fuzzy_object?(value) &&
43
+ aliased_matcher?(value) &&
44
44
  value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::HaveAttributes)
45
45
  end
46
46
 
47
47
  def self.a_collection_containing_exactly_something?(value)
48
- fuzzy_object?(value) &&
48
+ aliased_matcher?(value) &&
49
49
  value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::ContainExactly)
50
50
  end
51
51
 
52
52
  def self.a_kind_of_something?(value)
53
- fuzzy_object?(value) &&
53
+ aliased_matcher?(value) &&
54
54
  value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAKindOf)
55
55
  end
56
56
 
@@ -61,7 +61,7 @@ module SuperDiff
61
61
  end
62
62
 
63
63
  def self.an_instance_of_something?(value)
64
- fuzzy_object?(value) &&
64
+ aliased_matcher?(value) &&
65
65
  value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeAnInstanceOf)
66
66
  end
67
67
 
@@ -72,11 +72,11 @@ module SuperDiff
72
72
  end
73
73
 
74
74
  def self.a_value_within_something?(value)
75
- fuzzy_object?(value) &&
75
+ aliased_matcher?(value) &&
76
76
  value.base_matcher.is_a?(::RSpec::Matchers::BuiltIn::BeWithin)
77
77
  end
78
78
 
79
- def self.fuzzy_object?(value)
79
+ def self.aliased_matcher?(value)
80
80
  value.is_a?(::RSpec::Matchers::AliasedMatcher)
81
81
  end
82
82
 
@@ -112,7 +112,8 @@ module SuperDiff
112
112
  ObjectInspection::InspectionTreeBuilders::KindOf,
113
113
  ObjectInspection::InspectionTreeBuilders::ObjectHavingAttributes,
114
114
  # ObjectInspection::InspectionTreeBuilders::Primitive,
115
- ObjectInspection::InspectionTreeBuilders::ValueWithin
115
+ ObjectInspection::InspectionTreeBuilders::ValueWithin,
116
+ ObjectInspection::InspectionTreeBuilders::GenericDescribableMatcher
116
117
  )
117
118
  end
118
119
  end
@@ -1,3 +1,3 @@
1
1
  module SuperDiff
2
- VERSION = "0.10.0".freeze
2
+ VERSION = "0.11.0".freeze
3
3
  end
data/lib/super_diff.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "attr_extras/explicit"
2
2
  require "diff-lcs"
3
3
  require "patience_diff"
4
+ require "date"
4
5
 
5
6
  module SuperDiff
6
7
  autoload(
@@ -57,6 +58,14 @@ module SuperDiff
57
58
  value.is_a?(Time)
58
59
  end
59
60
 
61
+ def self.date_like?(value)
62
+ # Check for ActiveSupport's #acts_like_date? for their date-like objects
63
+ # In case class is both time-like and date-like, we should treat it as
64
+ # time-like. This is governed by the order of `Differs::DEFAULTS` entries
65
+ (value.respond_to?(:acts_like_date?) && value.acts_like_date?) ||
66
+ value.is_a?(Date)
67
+ end
68
+
60
69
  def self.primitive?(value)
61
70
  case value
62
71
  when true, false, nil, Symbol, Numeric, Regexp, Class