specdiff 0.3.0.pre.rc1 → 0.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/CHANGELOG.md +15 -1
- data/README.md +1 -2
- data/lib/specdiff/compare.rb +2 -2
- data/lib/specdiff/diff.rb +10 -7
- data/lib/specdiff/differ/{hashdiff.rb → hash.rb} +48 -34
- data/lib/specdiff/differ.rb +1 -1
- data/lib/specdiff/hashprint.rb +47 -27
- data/lib/specdiff/inspect.rb +94 -1
- data/lib/specdiff/rspec.rb +6 -13
- data/lib/specdiff/version.rb +1 -1
- data/lib/specdiff/webmock.rb +4 -2
- data/specdiff.gemspec +6 -7
- metadata +4 -20
- data/.rspec +0 -3
- data/.rubocop.yml +0 -203
- data/.tool-versions +0 -1
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -76
- data/Rakefile +0 -12
- data/assets/webmock_json_with_specdiff.png +0 -0
- data/assets/webmock_text_with_specdiff.png +0 -0
- data/examples/rspec/.rspec +0 -2
- data/examples/rspec/Gemfile +0 -10
- data/examples/rspec/Gemfile.lock +0 -52
- data/examples/rspec/spec/example_spec.rb +0 -678
- data/examples/rspec/spec/spec_helper.rb +0 -68
- data/examples/webmock/Gemfile +0 -6
- data/examples/webmock/Gemfile.lock +0 -50
- data/examples/webmock/json.rb +0 -37
- data/examples/webmock/text.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a33e470568352bc5fb3079f5aa3cf9933f5c02d7e28aae98847b9165a0d6a86
|
4
|
+
data.tar.gz: ad35a03f7da4fee967890515447eb0d2a2a4ec927d78d2458198177166aa43c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fa7b514db6ccb4a7216f317184e6de0dae0fb8ad762222c4d09ee589300ae4d71a38549710ceb8191e5276958fcdfc27e65dcb50f0353e64065492c58a28b8a
|
7
|
+
data.tar.gz: bf66592a0f9d787058dcdd3b27910863abdc70cdeb177ddfb84d6ddfa9973adee345fa8c90f821f6a8dbab94898db375414eeef8e9a306b532b9aa472f615280
|
data/.gitignore
ADDED
data/CHANGELOG.md
CHANGED
@@ -7,7 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
-
## [0.3.0-
|
10
|
+
## [0.3.0.rc2] - 2024-04-05
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- Rework how hashdiff's output gets printed.
|
15
|
+
- Rework switching heuristic between text diff/hashdiff in hash differ.
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- The RSpec integration now inspects hashes and arrays recursively. (Like rspec does by default)
|
20
|
+
- RSpec integration no longer breaks description output of matchers when using multi matchers (like .all or .and)
|
21
|
+
- The hash differ now deals with recursive hashes and arrays
|
22
|
+
- RSpec integration no longer breaks description output of matchers that are part of a diff inside an array or hash. (like when doing `match([have_attributes(...)])`)
|
23
|
+
|
24
|
+
## [0.3.0-rc1] - 2024-04-02
|
11
25
|
|
12
26
|
### Added
|
13
27
|
|
data/README.md
CHANGED
@@ -134,6 +134,7 @@ High level description of the heuristic specdiff implements
|
|
134
134
|
- [ ] unit tests are passing (`$ bundle exec rake test`)
|
135
135
|
- [ ] linter is happy (`$ bundle exec rake lint`)
|
136
136
|
- [ ] `examples/` look good
|
137
|
+
- [ ] check the package size using `$ bundle exec inspect_build`, make sure you haven't added any large files by accident
|
137
138
|
- [ ] update the version number in `version.rb`
|
138
139
|
- [ ] make sure the `examples/` `Gemfile.lock` files are updated (run bundle install)
|
139
140
|
- [ ] make sure `Gemfile.lock` is updated (run bundle install)
|
@@ -142,8 +143,6 @@ High level description of the heuristic specdiff implements
|
|
142
143
|
- [ ] make sure the pipeline is green
|
143
144
|
- [ ] `$ bundle exec rake release`
|
144
145
|
|
145
|
-
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
146
|
-
|
147
146
|
## Contributing
|
148
147
|
|
149
148
|
Bug reports and pull requests are welcome on GitHub at https://github.com/odinhb/specdiff.
|
data/lib/specdiff/compare.rb
CHANGED
@@ -80,9 +80,9 @@ private
|
|
80
80
|
elsif a.type == :text && b.type == :text
|
81
81
|
Specdiff::Differ::Text
|
82
82
|
elsif a.type == :hash && b.type == :hash
|
83
|
-
Specdiff::Differ::
|
83
|
+
Specdiff::Differ::Hash
|
84
84
|
elsif a.type == :array && b.type == :array
|
85
|
-
Specdiff::Differ::
|
85
|
+
Specdiff::Differ::Hash
|
86
86
|
else
|
87
87
|
Specdiff::Differ::NotFound
|
88
88
|
end
|
data/lib/specdiff/diff.rb
CHANGED
@@ -19,12 +19,15 @@
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def inspect
|
22
|
-
if empty?
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
raw_diff = if empty?
|
23
|
+
"empty"
|
24
|
+
elsif differ == ::Specdiff::Differ::Text
|
25
|
+
bytes = raw&.bytesize || 0
|
26
|
+
"#{bytes} bytes of #raw diff"
|
27
|
+
else
|
28
|
+
"#{raw.inspect}"
|
29
|
+
end
|
30
|
+
|
31
|
+
"<Specdiff::Diff (#{a.type}/#{b.type}) (#{differ}) (#{raw_diff})>"
|
29
32
|
end
|
30
33
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
require "hashdiff"
|
2
2
|
|
3
|
-
class Specdiff::Differ::
|
3
|
+
class Specdiff::Differ::Hash
|
4
4
|
extend ::Specdiff::Colorize
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
# The percentage of changes that must (potentially) be a key rename in a hash
|
7
|
+
# for text diffing to kick in. Expressed as a fraction of 1.
|
8
|
+
KEY_CHANGE_PERCENTAGE_THRESHOLD = 0.8
|
8
9
|
|
9
|
-
|
10
|
+
# The number of changes that must be detected by hashdiff before we print some
|
11
|
+
# extra newlines to better group extra/missing/new_values visually.
|
12
|
+
TOTAL_CHANGES_FOR_GROUPING_THRESHOLD = 9
|
10
13
|
|
11
14
|
def self.diff(a, b)
|
12
15
|
# array_path: true returns the path as an array, which differentiates
|
@@ -24,54 +27,60 @@ class Specdiff::Differ::Hashdiff
|
|
24
27
|
|
25
28
|
change_percentage = _calculate_change_percentage(hashdiff_diff)
|
26
29
|
|
27
|
-
if change_percentage
|
30
|
+
if change_percentage <= KEY_CHANGE_PERCENTAGE_THRESHOLD
|
28
31
|
hashdiff_diff
|
29
32
|
else
|
30
33
|
a_text = ::Specdiff.hashprint(a.value)
|
31
34
|
b_text = ::Specdiff.hashprint(b.value)
|
32
35
|
|
33
|
-
|
36
|
+
text_diff = ::Specdiff.diff(a_text, b_text)
|
34
37
|
|
35
|
-
if
|
38
|
+
if text_diff.empty?
|
36
39
|
[]
|
37
40
|
else
|
38
|
-
|
39
|
-
diff.b.type = b.type
|
40
|
-
|
41
|
-
diff
|
41
|
+
text_diff
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def self._calculate_change_percentage(hashdiff_diff)
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
extra_keys = hashdiff_diff.count { |element| element[0] == "+" }
|
48
|
+
missing_keys = hashdiff_diff.count { |element| element[0] == "-" }
|
49
|
+
new_values = hashdiff_diff.count { |element| element[0] == "~" }
|
50
50
|
# puts "hashdiff_diff: #{hashdiff_diff.inspect}"
|
51
|
-
# puts "
|
52
|
-
# puts "
|
53
|
-
# puts "
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
# puts "
|
65
|
-
|
66
|
-
|
51
|
+
# puts "extra_keys: #{extra_keys.inspect}"
|
52
|
+
# puts "missing_keys: #{missing_keys.inspect}"
|
53
|
+
# puts "new_values: #{new_values.inspect}"
|
54
|
+
|
55
|
+
potential_changed_keys = [extra_keys, missing_keys].min
|
56
|
+
adjusted_extra_keys = extra_keys - potential_changed_keys
|
57
|
+
adjusted_missing_keys = missing_keys - potential_changed_keys
|
58
|
+
# puts "potential_changed_keys: #{potential_changed_keys.inspect}"
|
59
|
+
# puts "adjusted_extra_keys: #{adjusted_extra_keys.inspect}"
|
60
|
+
# puts "adjusted_missing_keys: #{adjusted_missing_keys.inspect}"
|
61
|
+
|
62
|
+
non_changed_keys = adjusted_extra_keys + adjusted_missing_keys + new_values
|
63
|
+
total_changes = non_changed_keys + potential_changed_keys
|
64
|
+
# puts "non_changed_keys: #{non_changed_keys.inspect}"
|
65
|
+
# puts "total_changes: #{total_changes.inspect}"
|
66
|
+
|
67
|
+
key_change_fraction = Rational(potential_changed_keys, total_changes)
|
68
|
+
key_change_percentage = key_change_fraction.to_f
|
69
|
+
# puts "key_change_fraction: #{key_change_fraction.inspect}"
|
70
|
+
# puts "key_change_percentage: #{key_change_percentage.inspect}"
|
71
|
+
|
72
|
+
key_change_percentage
|
67
73
|
end
|
68
74
|
|
69
75
|
def self.empty?(diff)
|
70
76
|
diff.raw.empty?
|
71
77
|
end
|
72
78
|
|
79
|
+
NEWLINE = "\n"
|
80
|
+
|
73
81
|
def self.stringify(diff)
|
74
82
|
result = +""
|
83
|
+
return result if diff.empty?
|
75
84
|
|
76
85
|
total_changes = diff.raw.size
|
77
86
|
group_with_newlines = total_changes >= TOTAL_CHANGES_FOR_GROUPING_THRESHOLD
|
@@ -92,6 +101,9 @@ class Specdiff::Differ::Hashdiff
|
|
92
101
|
additions = changes_grouped_by_type["+"] || []
|
93
102
|
value_changes = changes_grouped_by_type["~"] || []
|
94
103
|
|
104
|
+
result << "@@ +#{additions.size}/-#{deletions.size}/~#{value_changes.size} @@"
|
105
|
+
result << NEWLINE
|
106
|
+
|
95
107
|
deletions.each do |change|
|
96
108
|
value = change[2]
|
97
109
|
path = _stringify_path(change[1])
|
@@ -108,7 +120,7 @@ class Specdiff::Differ::Hashdiff
|
|
108
120
|
value = change[2]
|
109
121
|
path = _stringify_path(change[1])
|
110
122
|
|
111
|
-
result << "
|
123
|
+
result << " extra key: #{path} (#{::Specdiff.diff_inspect(value)})"
|
112
124
|
result << NEWLINE
|
113
125
|
end
|
114
126
|
|
@@ -123,17 +135,19 @@ class Specdiff::Differ::Hashdiff
|
|
123
135
|
|
124
136
|
from_inspected = ::Specdiff.diff_inspect(from)
|
125
137
|
to_inspected = ::Specdiff.diff_inspect(to)
|
126
|
-
result << "
|
138
|
+
result << " new value: #{path} (#{from_inspected} -> #{to_inspected})"
|
127
139
|
result << NEWLINE
|
128
140
|
end
|
129
141
|
|
130
142
|
colorize_by_line(result) do |line|
|
131
143
|
if line.start_with?("missing key:")
|
132
144
|
red(line)
|
133
|
-
elsif line.start_with?(
|
145
|
+
elsif line.start_with?(" extra key:")
|
134
146
|
green(line)
|
135
|
-
elsif line.start_with?("
|
147
|
+
elsif line.start_with?(" new value:")
|
136
148
|
yellow(line)
|
149
|
+
elsif line.start_with?("@@")
|
150
|
+
cyan(line)
|
137
151
|
else
|
138
152
|
reset_color(line)
|
139
153
|
end
|
data/lib/specdiff/differ.rb
CHANGED
data/lib/specdiff/hashprint.rb
CHANGED
@@ -13,6 +13,7 @@ class Specdiff::Hashprint
|
|
13
13
|
NEWLINE = "\n".freeze
|
14
14
|
|
15
15
|
def call(thing)
|
16
|
+
@recursion_trail = []
|
16
17
|
@indentation_level = 0
|
17
18
|
@indentation_per_level = SPACE * INDENTATION_SPACES
|
18
19
|
@indent = ""
|
@@ -41,17 +42,6 @@ private
|
|
41
42
|
recalculate_indent
|
42
43
|
end
|
43
44
|
|
44
|
-
def with_indentation_level(temporary_level)
|
45
|
-
old_level = @indentation_level
|
46
|
-
@indentation_level = temporary_level
|
47
|
-
recalculate_indent
|
48
|
-
|
49
|
-
yield
|
50
|
-
|
51
|
-
@indentation_level = old_level
|
52
|
-
recalculate_indent
|
53
|
-
end
|
54
|
-
|
55
45
|
def skip_next_opening_indent
|
56
46
|
@skip_next_opening_indent = true
|
57
47
|
|
@@ -67,11 +57,24 @@ private
|
|
67
57
|
end
|
68
58
|
end
|
69
59
|
|
60
|
+
def track_recursion(thing)
|
61
|
+
@recursion_trail.push(thing)
|
62
|
+
result = yield
|
63
|
+
@recursion_trail.pop
|
64
|
+
result
|
65
|
+
end
|
66
|
+
|
67
|
+
def deja_vu?(current_place)
|
68
|
+
@recursion_trail.any? { |previous_place| previous_place == current_place }
|
69
|
+
end
|
70
|
+
|
70
71
|
# #=== allows us to rely on Module implementing #=== instead of relying on the
|
71
72
|
# thing (which could be any kind of wacky object) having to implement
|
72
73
|
# #is_a? or #kind_of?
|
73
74
|
def output(thing)
|
74
|
-
if
|
75
|
+
if deja_vu?(thing)
|
76
|
+
output_deja_vu(thing)
|
77
|
+
elsif Hash === thing
|
75
78
|
output_hash(thing)
|
76
79
|
elsif Array === thing
|
77
80
|
output_array(thing)
|
@@ -89,10 +92,10 @@ private
|
|
89
92
|
@output << @indent unless this_indent_should_be_skipped
|
90
93
|
|
91
94
|
@output << HASH_OPEN
|
92
|
-
|
93
|
-
@output << NEWLINE
|
95
|
+
@output << NEWLINE
|
94
96
|
|
95
|
-
|
97
|
+
increase_indentation
|
98
|
+
track_recursion(hash) do
|
96
99
|
hash.each do |key, value|
|
97
100
|
@output << @indent
|
98
101
|
|
@@ -113,11 +116,10 @@ private
|
|
113
116
|
@output << COMMA
|
114
117
|
@output << NEWLINE
|
115
118
|
end
|
116
|
-
|
117
|
-
|
118
|
-
@output << @indent
|
119
|
-
# end
|
119
|
+
end
|
120
|
+
decrease_indentation
|
120
121
|
|
122
|
+
@output << @indent
|
121
123
|
@output << HASH_CLOSE
|
122
124
|
end
|
123
125
|
|
@@ -128,21 +130,19 @@ private
|
|
128
130
|
@output << @indent unless this_indent_should_be_skipped
|
129
131
|
|
130
132
|
@output << ARRAY_OPEN
|
133
|
+
@output << NEWLINE
|
131
134
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
increase_indentation
|
135
|
+
increase_indentation
|
136
|
+
track_recursion(array) do
|
136
137
|
array.each do |element|
|
137
138
|
output(element)
|
138
139
|
@output << COMMA
|
139
140
|
@output << NEWLINE
|
140
141
|
end
|
141
|
-
|
142
|
-
|
143
|
-
@output << @indent
|
144
|
-
# end
|
142
|
+
end
|
143
|
+
decrease_indentation
|
145
144
|
|
145
|
+
@output << @indent
|
146
146
|
@output << ARRAY_CLOSE
|
147
147
|
end
|
148
148
|
|
@@ -151,4 +151,24 @@ private
|
|
151
151
|
|
152
152
|
@output << ::Specdiff.diff_inspect(thing)
|
153
153
|
end
|
154
|
+
|
155
|
+
# The stdlib inspect code returns this when you have recursive structures.
|
156
|
+
STANDARD_INSPECT_RECURSIVE_ARRAY = "[...]".freeze
|
157
|
+
STANDARD_INSPECT_RECURSIVE_HASH = "{...}".freeze
|
158
|
+
|
159
|
+
def output_deja_vu(thing)
|
160
|
+
@output << @indent unless this_indent_should_be_skipped
|
161
|
+
|
162
|
+
case thing
|
163
|
+
when Array
|
164
|
+
# "#<Array ##{thing.object_id}>"
|
165
|
+
@output << STANDARD_INSPECT_RECURSIVE_ARRAY
|
166
|
+
when Hash
|
167
|
+
# "#<Hash ##{thing.object_id}>"
|
168
|
+
@output << STANDARD_INSPECT_RECURSIVE_HASH
|
169
|
+
else
|
170
|
+
# this should never happen
|
171
|
+
raise "Specdiff::Hashprint missing deja vu for: #{thing.inspect}"
|
172
|
+
end
|
173
|
+
end
|
154
174
|
end
|
data/lib/specdiff/inspect.rb
CHANGED
@@ -6,11 +6,17 @@ class Specdiff::Inspect
|
|
6
6
|
new.call(...)
|
7
7
|
end
|
8
8
|
|
9
|
+
def initialize
|
10
|
+
@recursion_trail = []
|
11
|
+
end
|
12
|
+
|
9
13
|
# #=== allows us to rely on Module implementing #=== instead of relying on the
|
10
14
|
# thing (which could be any kind of wacky object) having to implement
|
11
15
|
# #is_a? or #kind_of?
|
12
16
|
def call(thing)
|
13
|
-
if
|
17
|
+
if Hash === thing || Array === thing
|
18
|
+
recursive_replace_inspect(thing).inspect
|
19
|
+
elsif Time === thing
|
14
20
|
"#<Time: #{thing.strftime(TIME_FORMAT)}>"
|
15
21
|
elsif DateTime === thing
|
16
22
|
"#<DateTime: #{thing.rfc3339}>"
|
@@ -18,6 +24,12 @@ class Specdiff::Inspect
|
|
18
24
|
"#<Date: #{thing.strftime(DATE_FORMAT)}>"
|
19
25
|
elsif defined?(BigDecimal) && BigDecimal === thing
|
20
26
|
"#<BigDecimal: #{thing.to_s('F')}>"
|
27
|
+
elsif rspec_matcher?(thing)
|
28
|
+
# Turns out rspec depends on the recursion in its inspection logic to
|
29
|
+
# print the "description" of rspec matchers, in situations such as when
|
30
|
+
# using multi-matchers (.all, .or or .and), or when nesting them inside
|
31
|
+
# eachother (such as match([have_attributes(...)])).
|
32
|
+
thing.description
|
21
33
|
else
|
22
34
|
begin
|
23
35
|
thing.inspect
|
@@ -27,6 +39,12 @@ class Specdiff::Inspect
|
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
42
|
+
private def rspec_matcher?(thing)
|
43
|
+
defined?(::Specdiff::RSpecIntegration) &&
|
44
|
+
::RSpec::Support.is_a_matcher?(thing) &&
|
45
|
+
thing.respond_to?(:description)
|
46
|
+
end
|
47
|
+
|
30
48
|
private def inspect_anyway(uninspectable)
|
31
49
|
"#<uninspectable #{class_of(uninspectable)}>"
|
32
50
|
end
|
@@ -38,4 +56,79 @@ class Specdiff::Inspect
|
|
38
56
|
singleton_class.ancestors
|
39
57
|
.find { |ancestor| !ancestor.equal?(singleton_class) }
|
40
58
|
end
|
59
|
+
|
60
|
+
# recursion below
|
61
|
+
|
62
|
+
InspectWrapper = Struct.new(:text) do
|
63
|
+
def inspect
|
64
|
+
text
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private def recursive_replace_inspect(thing)
|
69
|
+
if deja_vu?(thing)
|
70
|
+
# I've just been in this place before
|
71
|
+
# And I know it's my time to go...
|
72
|
+
return InspectWrapper.new(inspect_deja_vu(thing))
|
73
|
+
end
|
74
|
+
|
75
|
+
case thing
|
76
|
+
when Array
|
77
|
+
track_recursion(thing) do
|
78
|
+
thing.map { |element| recursive_replace_inspect(element) }
|
79
|
+
end
|
80
|
+
when Hash
|
81
|
+
track_recursion(thing) do
|
82
|
+
new_hash = {}
|
83
|
+
|
84
|
+
thing.each do |key, value|
|
85
|
+
new_hash[recursive_replace_inspect(key)] = recursive_replace_inspect(value)
|
86
|
+
end
|
87
|
+
|
88
|
+
new_hash
|
89
|
+
end
|
90
|
+
else
|
91
|
+
wrap_inspect(thing)
|
92
|
+
end
|
93
|
+
rescue SystemStackError => e
|
94
|
+
wrap_inspect(
|
95
|
+
thing,
|
96
|
+
text: "#{e.class}: #{e.message}\n\n" \
|
97
|
+
"encountered when inspecting #{thing.inspect}"
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
private def track_recursion(thing)
|
102
|
+
@recursion_trail.push(thing)
|
103
|
+
result = yield
|
104
|
+
@recursion_trail.pop
|
105
|
+
result
|
106
|
+
end
|
107
|
+
|
108
|
+
private def deja_vu?(current_place)
|
109
|
+
@recursion_trail.any? { |previous_place| previous_place == current_place }
|
110
|
+
end
|
111
|
+
|
112
|
+
private def wrap_inspect(thing, text: :_use_diff_inspect)
|
113
|
+
text = call(thing) if text == :_use_diff_inspect
|
114
|
+
InspectWrapper.new(text)
|
115
|
+
end
|
116
|
+
|
117
|
+
# The stdlib inspect code returns this when you have recursive structures.
|
118
|
+
STANDARD_INSPECT_RECURSIVE_ARRAY = "[...]".freeze
|
119
|
+
STANDARD_INSPECT_RECURSIVE_HASH = "{...}".freeze
|
120
|
+
|
121
|
+
private def inspect_deja_vu(thing)
|
122
|
+
case thing
|
123
|
+
when Array
|
124
|
+
# "#<Array ##{thing.object_id}>"
|
125
|
+
STANDARD_INSPECT_RECURSIVE_ARRAY
|
126
|
+
when Hash
|
127
|
+
# "#<Hash ##{thing.object_id}>"
|
128
|
+
STANDARD_INSPECT_RECURSIVE_HASH
|
129
|
+
else
|
130
|
+
# this should never happen
|
131
|
+
raise "Specdiff::Inspect missing deja vu for: #{thing.inspect}"
|
132
|
+
end
|
133
|
+
end
|
41
134
|
end
|
data/lib/specdiff/rspec.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
raise "rspec must be required before specdiff/rspec!" unless defined?(RSpec)
|
2
|
+
raise "RSpec::Support is missing????" unless defined?(RSpec::Support)
|
3
|
+
|
1
4
|
class RSpec::Support::Differ
|
2
5
|
alias old_diff diff
|
3
6
|
|
@@ -14,20 +17,10 @@ end
|
|
14
17
|
# This stops rspec from truncating strings w/ ellipsis, as well as making the
|
15
18
|
# "inspect" output consistent with specdiff's.
|
16
19
|
class RSpec::Support::ObjectFormatter
|
17
|
-
class SpecdiffCustomInspector < BaseInspector
|
18
|
-
def self.can_inspect?(_)
|
19
|
-
true
|
20
|
-
end
|
21
|
-
|
22
|
-
def inspect
|
23
|
-
::Specdiff.diff_inspect(object)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
remove_const("INSPECTOR_CLASSES")
|
28
|
-
const_set("INSPECTOR_CLASSES", [SpecdiffCustomInspector])
|
29
|
-
|
30
20
|
def format(object)
|
31
21
|
::Specdiff.diff_inspect(object)
|
32
22
|
end
|
33
23
|
end
|
24
|
+
|
25
|
+
# marker for successfully loading this integration
|
26
|
+
class Specdiff::RSpecIntegration; end # rubocop: disable Lint/EmptyClass
|
data/lib/specdiff/version.rb
CHANGED
data/lib/specdiff/webmock.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require "json"
|
1
|
+
raise "webmock must be required before specdiff/webmock" unless defined?(WebMock)
|
3
2
|
|
4
3
|
module WebMock
|
5
4
|
class RequestBodyDiff
|
@@ -39,3 +38,6 @@ module WebMock
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
end
|
41
|
+
|
42
|
+
# marker for successfully loading this integration
|
43
|
+
class Specdiff::WebmockIntegration; end # rubocop: disable Lint/EmptyClass
|
data/specdiff.gemspec
CHANGED
@@ -17,13 +17,12 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.metadata["source_code_uri"] = spec.homepage
|
18
18
|
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
20
|
+
spec.files =
|
21
|
+
Dir["*.gemspec"] +
|
22
|
+
Dir["*.md"] +
|
23
|
+
Dir["*.txt"] +
|
24
|
+
Dir[".gitignore"] +
|
25
|
+
Dir["lib/**/*.rb"]
|
27
26
|
spec.require_paths = ["lib"]
|
28
27
|
|
29
28
|
spec.add_dependency "hashdiff", "~> 1.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: specdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0.
|
4
|
+
version: 0.3.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Odin Heggvold Bekkelund
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-04-
|
11
|
+
date: 2024-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashdiff
|
@@ -45,26 +45,10 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- ".
|
49
|
-
- ".rubocop.yml"
|
50
|
-
- ".tool-versions"
|
48
|
+
- ".gitignore"
|
51
49
|
- CHANGELOG.md
|
52
|
-
- Gemfile
|
53
|
-
- Gemfile.lock
|
54
50
|
- LICENSE.txt
|
55
51
|
- README.md
|
56
|
-
- Rakefile
|
57
|
-
- assets/webmock_json_with_specdiff.png
|
58
|
-
- assets/webmock_text_with_specdiff.png
|
59
|
-
- examples/rspec/.rspec
|
60
|
-
- examples/rspec/Gemfile
|
61
|
-
- examples/rspec/Gemfile.lock
|
62
|
-
- examples/rspec/spec/example_spec.rb
|
63
|
-
- examples/rspec/spec/spec_helper.rb
|
64
|
-
- examples/webmock/Gemfile
|
65
|
-
- examples/webmock/Gemfile.lock
|
66
|
-
- examples/webmock/json.rb
|
67
|
-
- examples/webmock/text.rb
|
68
52
|
- glossary.txt
|
69
53
|
- lib/specdiff.rb
|
70
54
|
- lib/specdiff/colorize.rb
|
@@ -72,7 +56,7 @@ files:
|
|
72
56
|
- lib/specdiff/config.rb
|
73
57
|
- lib/specdiff/diff.rb
|
74
58
|
- lib/specdiff/differ.rb
|
75
|
-
- lib/specdiff/differ/
|
59
|
+
- lib/specdiff/differ/hash.rb
|
76
60
|
- lib/specdiff/differ/not_found.rb
|
77
61
|
- lib/specdiff/differ/text.rb
|
78
62
|
- lib/specdiff/hashprint.rb
|
data/.rspec
DELETED