specdiff 0.1.1 → 0.3.0.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/Gemfile.lock +1 -1
- data/README.md +70 -4
- data/assets/webmock_json_with_specdiff.png +0 -0
- data/assets/webmock_text_with_specdiff.png +0 -0
- data/examples/rspec/.rspec +2 -0
- data/examples/rspec/Gemfile +10 -0
- data/examples/rspec/Gemfile.lock +52 -0
- data/examples/rspec/spec/example_spec.rb +678 -0
- data/examples/rspec/spec/spec_helper.rb +68 -0
- data/examples/webmock/Gemfile.lock +2 -2
- data/glossary.txt +27 -5
- data/lib/specdiff/colorize.rb +5 -0
- data/lib/specdiff/compare.rb +95 -0
- data/lib/specdiff/config.rb +9 -6
- data/lib/specdiff/diff.rb +3 -1
- data/lib/specdiff/differ/hashdiff.rb +101 -25
- data/lib/specdiff/differ/not_found.rb +1 -1
- data/lib/specdiff/differ/text.rb +21 -7
- data/lib/specdiff/differ.rb +1 -94
- data/lib/specdiff/hashprint.rb +154 -0
- data/lib/specdiff/inspect.rb +41 -0
- data/lib/specdiff/plugins.rb +5 -7
- data/lib/specdiff/rspec.rb +33 -0
- data/lib/specdiff/version.rb +1 -1
- data/lib/specdiff/webmock.rb +41 -1
- data/lib/specdiff.rb +17 -3
- metadata +20 -11
- data/lib/specdiff/threadlocal.rb +0 -8
- data/lib/specdiff/webmock/request_body_diff.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68cf98631e494fb5f016c0b3632cce58f616dad54ba11c782b37e3de4f2b36c9
|
4
|
+
data.tar.gz: b97fee8a8e586b383a71bf0dcdcb32be7cf1c135356a90ec2ae7488fc2082071
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b374cadd1aa564cf8252c4b3d6c4ca2be952b147891cdbec9f0799383349bf5bcf61a1ef94979bc2b1f7dbe4d850e586d4c11f1271c74a14dc9be09cffc4e184
|
7
|
+
data.tar.gz: 8379b0c263ae20900ec31b63ea9600e3c15cef8fe9b597c1e1349a708c323d03ee8bfaa46d6f6eeb666e2af0ee751e7ef2cd47917e927eeceb48a7f076a1e126
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,33 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
1
8
|
## [Unreleased]
|
2
9
|
|
10
|
+
## [0.3.0-rc1]
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Add rspec integration. `require "specdiff/rspec"` The rspec integration will cause rspec's differ to be replaced entirely with specdiff. It will also cause rspec's inspect (object formatter) to be replaced with Specdiff's inspect.
|
15
|
+
- Add `Specdiff.diff_inspect` method, which is a wrapper for `#inspect` with some extra logic to make diffs look better.
|
16
|
+
- Add `Specdiff.hashprint` method, which prints hashes/arrays recursively in a way that is friendly to a text differ.
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Improve contrast for some elements of the text differ
|
21
|
+
- Improve hash diffing. Introduce heuristic that decides whether a text diff of the hashes or the hashdiff gem's output is better for the situation.
|
22
|
+
- No longer produces a text diff of booleans
|
23
|
+
- No longer produces a text diff if both strings are a single line. (This would be useless since the diff is line-based.)
|
24
|
+
|
25
|
+
## [0.2.0] - 2023-12-04
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
|
29
|
+
- Stop using thread locals ([#1](https://github.com/odinhb/specdiff/pull/1))
|
30
|
+
|
3
31
|
## [0.1.1] - 2023-12-04
|
4
32
|
|
5
33
|
### Fixed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,24 @@ dropping the content type requirement.
|
|
11
11
|
Specdiff automagically detects the types of provided data and prints a suitable
|
12
12
|
diff between them.
|
13
13
|
|
14
|
-
|
14
|
+
## Cool, what does it look like?
|
15
|
+
|
16
|
+
When specdiff is enabled, webmock will produce a generic text diff using
|
17
|
+
[`Diff::LCS`](https://github.com/halostatue/diff-lcs) (basically the same
|
18
|
+
diff as rspec uses):
|
19
|
+
|
20
|
+
![webmock_text_with_specdiff](./assets/webmock_text_with_specdiff.png)
|
21
|
+
|
22
|
+
It will also produce a json [hashdiff](https://github.com/liufengyun/hashdiff),
|
23
|
+
even if the request did not have the content type header:
|
24
|
+
|
25
|
+
![d](./assets/webmock_json_with_specdiff.png)
|
26
|
+
|
27
|
+
(The output of the json diff is experimental, feedback would be great!)
|
28
|
+
|
29
|
+
You might also check out the `examples/` directory to play with it:
|
30
|
+
|
31
|
+
`$ cd examples/webmock && bundle install`
|
15
32
|
|
16
33
|
## Installation
|
17
34
|
|
@@ -47,8 +64,10 @@ Specdiff.configure do |config|
|
|
47
64
|
end
|
48
65
|
```
|
49
66
|
|
50
|
-
|
51
|
-
|
67
|
+
### WebMock
|
68
|
+
|
69
|
+
The webmock patch should make webmock show request body diffs by using the
|
70
|
+
specdiff gem when stubs mismatch. It only applies to request bodies.
|
52
71
|
|
53
72
|
### Direct usage
|
54
73
|
|
@@ -71,10 +90,13 @@ Specdiff.load!(:json)
|
|
71
90
|
Specdiff.load!(MyCustomType)
|
72
91
|
```
|
73
92
|
|
74
|
-
Check out the
|
93
|
+
[Check out the source code](./lib/specdiff/plugins/json.rb) to learn the plugin interface.
|
75
94
|
|
76
95
|
## Development
|
77
96
|
|
97
|
+
Check out the [glossary](./glossary.txt) to make sure you (and I) are using the
|
98
|
+
same words for things ;)
|
99
|
+
|
78
100
|
Install the software versions specified in `.tool-versions`.
|
79
101
|
|
80
102
|
Run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and linter and make sure they're green before starting to make your changes.
|
@@ -83,8 +105,43 @@ Run `bundle exec rake -AD` for a full list of all the available tasks you may us
|
|
83
105
|
|
84
106
|
You can also run `bin/console` for an interactive prompt that will allow you to experiment with the gem code loaded.
|
85
107
|
|
108
|
+
Remember to update the unreleased section of the [changelog](./CHANGELOG.md) before you submit your pull request.
|
109
|
+
|
110
|
+
## How it works/"Architecture"
|
111
|
+
|
112
|
+
High level description of the heuristic specdiff implements
|
113
|
+
|
114
|
+
1. receive 2 pieces of data: `a` and `b`
|
115
|
+
2. determine types for `a` and `b`
|
116
|
+
1. test against plugin types
|
117
|
+
2. test against built in types
|
118
|
+
3. fall back to the `:unknown` type
|
119
|
+
3. determine which differ is appropriate for the types
|
120
|
+
1. test against plugin differs
|
121
|
+
2. test against built in differs
|
122
|
+
3. fall back to the null differ (`NotFound`)
|
123
|
+
7. run the selected differ with a and b
|
124
|
+
8. package it into a `::Specdiff::Diff` which records the detected types
|
125
|
+
|
126
|
+
\<time passes>
|
127
|
+
|
128
|
+
6. at some point later when `#to_s` is invoked, stringify the diff using the differ's `#stringify`
|
129
|
+
|
86
130
|
## Releasing
|
87
131
|
|
132
|
+
### Release procedure
|
133
|
+
|
134
|
+
- [ ] unit tests are passing (`$ bundle exec rake test`)
|
135
|
+
- [ ] linter is happy (`$ bundle exec rake lint`)
|
136
|
+
- [ ] `examples/` look good
|
137
|
+
- [ ] update the version number in `version.rb`
|
138
|
+
- [ ] make sure the `examples/` `Gemfile.lock` files are updated (run bundle install)
|
139
|
+
- [ ] make sure `Gemfile.lock` is updated (run bundle install)
|
140
|
+
- [ ] move unreleased changes to the next version in the [changelog](./CHANGELOG.md)
|
141
|
+
- [ ] commit in the form "vX.X.X" and push
|
142
|
+
- [ ] make sure the pipeline is green
|
143
|
+
- [ ] `$ bundle exec rake release`
|
144
|
+
|
88
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).
|
89
146
|
|
90
147
|
## Contributing
|
@@ -94,3 +151,12 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/odinhb
|
|
94
151
|
## License
|
95
152
|
|
96
153
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
154
|
+
|
155
|
+
## TODO
|
156
|
+
|
157
|
+
This documents potential improvements/issues I know about or have thought about.
|
158
|
+
|
159
|
+
- [ ] test the webmock monkey-patch. currently there is an empty webmock_spec.rb (should we do this using rspec?) and the examples/ directory contains a few webmock examples (which are a good idea to run before releasing) but it would be nice to have the pipeline fail if it doesn't work for whatever reason
|
160
|
+
- [ ] finalize plugin interface (are the methods named intuitively? should we split type detector definitions and differ definitions?)
|
161
|
+
- [ ] document how to define a plugin properly (instead of just linking to the source code)
|
162
|
+
- [ ] is the stringification of hashdiff's output really better than pretty print? or just more wordy? (the colors are definitely nice)
|
Binary file
|
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../..
|
3
|
+
specs:
|
4
|
+
specdiff (0.3.0.pre.rc1)
|
5
|
+
diff-lcs (~> 1.5)
|
6
|
+
hashdiff (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
bigdecimal (3.1.7)
|
12
|
+
debug (1.9.1)
|
13
|
+
irb (~> 1.10)
|
14
|
+
reline (>= 0.3.8)
|
15
|
+
diff-lcs (1.5.1)
|
16
|
+
hashdiff (1.1.0)
|
17
|
+
io-console (0.7.2)
|
18
|
+
irb (1.12.0)
|
19
|
+
rdoc
|
20
|
+
reline (>= 0.4.2)
|
21
|
+
psych (5.1.2)
|
22
|
+
stringio
|
23
|
+
rdoc (6.6.2)
|
24
|
+
psych (>= 4.0.0)
|
25
|
+
reline (0.4.3)
|
26
|
+
io-console (~> 0.5)
|
27
|
+
rspec (3.13.0)
|
28
|
+
rspec-core (~> 3.13.0)
|
29
|
+
rspec-expectations (~> 3.13.0)
|
30
|
+
rspec-mocks (~> 3.13.0)
|
31
|
+
rspec-core (3.13.0)
|
32
|
+
rspec-support (~> 3.13.0)
|
33
|
+
rspec-expectations (3.13.0)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.13.0)
|
36
|
+
rspec-mocks (3.13.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.13.0)
|
39
|
+
rspec-support (3.13.1)
|
40
|
+
stringio (3.1.0)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
x86_64-linux
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bigdecimal
|
47
|
+
debug
|
48
|
+
rspec
|
49
|
+
specdiff!
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
2.3.5
|