7
7
[ hound-badge ] : https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
8
8
[ hound ] : https://houndci.com
9
9
10
- SuperDiff is a gem that hooks into RSpec to intelligently display the
11
- differences between two data structures of any type.
10
+ SuperDiff is a gem that hooks into RSpec
11
+ to intelligently display the differences between two data structures of any type.
12
12
13
13
📢 ** [ See what's changed in the latest version (0.4.0)] [ changelog ] .**
14
14
15
15
[ changelog ] : CHANGELOG.md
16
16
17
17
## Introduction
18
18
19
- The primary motivation behind this gem is to vastly improve upon RSpec's
20
- built-in diffing capabilities.
19
+ The primary motivation behind this gem
20
+ is to vastly improve upon RSpec's built-in diffing capabilities.
21
21
22
- Sometimes, whenever you use a matcher such as ` eq ` , ` match ` , ` include ` , or
23
- ` have_attributes ` , you will get a diff of the two data structures you are trying
24
- to match against. This is great if all you want to do is compare multi-line
25
- strings. But if you want to compare other, more "real world" kinds of values —
26
- nested data structures (arrays, hashes, and full-scale objects), such as what
27
- you might work with when developing API endpoints or testing methods that make
28
- database calls and return a set of model objects — then you are out of luck.
29
- Since [ RSpec merely runs your ` expected ` and ` actual ` values through Ruby's
30
- PrettyPrinter library ] [ rspec-differ-fail ] and then performs a diff of these
31
- strings, the output it produces leaves much to be desired.
22
+ Sometimes, whenever you use a matcher such as ` eq ` , ` match ` , ` include ` , or ` have_attributes ` ,
23
+ you will get a diff of the two data structures you are trying to match against.
24
+ This is great if all you want to do is compare multi-line strings.
25
+ But if you want to compare other, more "real world" kinds of values,
26
+ such as what you might work with when developing API endpoints
27
+ or testing methods that make database calls and return a set of model objects,
28
+ then you are out of luck.
29
+ Since [ RSpec merely runs your ` expected ` and ` actual ` values through Ruby's PrettyPrinter library ] [ rspec-differ-fail ]
30
+ and then performs a diff of these strings,
31
+ the output it produces leaves much to be desired.
32
32
33
33
[ rspec-differ-fail ] : https://github.com/rspec/rspec-support/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
34
34
35
- For instance, let's say you wanted to compare these two hashes:
35
+ For instance,
36
+ let's say you wanted to compare these two hashes:
36
37
37
38
``` ruby
38
39
actual = {
@@ -86,36 +87,60 @@ You would get output that looks like this:
86
87
87
88
![ Before super_diff] ( doc/before.png )
88
89
89
- What this library does is to provide a diff engine that knows how to figure out
90
- the differences between any two data structures and display them in a sensible
91
- way. So, using the example above, you'd get this instead:
90
+ What this library does
91
+ is to provide a diff engine
92
+ that knows how to figure out the differences between any two data structures
93
+ and display them in a sensible way.
94
+ So, using the example above,
95
+ you'd get this instead:
92
96
93
97
![ After super_diff] ( doc/after.png )
94
98
95
99
## Installation
96
100
97
- Want to try out this gem for yourself? As with most development-related gems,
98
- there are a couple ways depending on your type of project:
101
+ There are a few different ways to install ` super_diff `
102
+ depending on your type of project.
99
103
100
104
### Rails apps
101
105
102
- If you're developing a Rails app, add the following to your Gemfile:
106
+ If you're developing a Rails app,
107
+ add the following to your Gemfile:
103
108
104
109
``` ruby
105
- gem " super_diff"
110
+ group :test do
111
+ gem " super_diff"
112
+ end
106
113
```
107
114
108
- After running ` bundle install ` , add the following to your ` rails_helper ` :
115
+ After running ` bundle install ` ,
116
+ add the following to your ` rails_helper ` :
109
117
110
118
``` ruby
111
119
require " super_diff/rspec-rails"
112
120
```
113
121
114
- You're done!
122
+ ### Projects using some part of Rails (e.g. ActiveModel)
115
123
116
- ### Libraries
124
+ If you're developing an app using Hanami or Sinatra,
125
+ or merely using a part of Rails such as ActiveModel,
126
+ add the following to your Gemfile where appropriate:
117
127
118
- If you're developing a library, add the following to your gemspec:
128
+ ``` ruby
129
+ gem " super_diff"
130
+ ```
131
+
132
+ After running ` bundle install ` ,
133
+ add the following to your ` spec_helper ` :
134
+
135
+ ``` ruby
136
+ require " super_diff/rspec"
137
+ require " super_diff/active_support"
138
+ ```
139
+
140
+ ### Gems
141
+
142
+ If you're developing a gem,
143
+ add the following to your gemspec:
119
144
120
145
``` ruby
121
146
spec.add_development_dependency " super_diff"
@@ -127,14 +152,16 @@ Now add the following to your `spec_helper`:
127
152
require " super_diff/rspec"
128
153
```
129
154
130
- You're done!
131
-
132
155
## Configuration
133
156
134
- As capable as this library is, it doesn't know how to deal with every kind of
135
- object out there. You might find it necessary to instruct the gem on how to diff
136
- your object. To do this, you can use a configuration block. Simply add this to
137
- your test helper file (` rails_helper ` or ` spec_helper ` ):
157
+ As capable as this library is,
158
+ it doesn't know how to deal with every kind of object out there.
159
+ If you have a custom class,
160
+ and instances of your class aren't appearing in diffs like you like,
161
+ you might find it necessary to instruct the gem on how to handle them.
162
+ In that case
163
+ you would add something like this to your test helper file
164
+ (` rails_helper ` or ` spec_helper ` ):
138
165
139
166
``` ruby
140
167
SuperDiff ::RSpec .configure do |config |
@@ -144,62 +171,53 @@ SuperDiff::RSpec.configure do |config|
144
171
end
145
172
```
146
173
147
- * (More info here in the future on adding a custom differ, operational sequencer,
148
- and diff formatter. Also explanations on what these are.)*
174
+ * (More info here in the future on adding a custom differ, operational sequencer, and diff formatter.
175
+ Also explanations on what these are.)*
149
176
150
- ## Contributing
151
-
152
- If you encounter a bug or have an idea for how this could be better, feel free
153
- to [ create an issue] ( https://github.com/mcmire/super_diff/issues ) .
154
-
155
- If you'd like to submit a PR instead, here's how to get started. First, fork
156
- this repo. Then, when you've cloned your fork, run:
157
-
158
- ```
159
- bin/setup
160
- ```
177
+ ## Support
161
178
162
- This will install various dependencies. After this, you can run all of the
163
- tests:
179
+ My goal for this library is to improve your development experience.
180
+ If this is not the case,
181
+ and you encounter a bug or have a suggestion,
182
+ feel free to [ create an issue] [ issues-list ] .
183
+ I'll try to respond to it as soon as I can!
164
184
165
- ```
166
- bundle exec rake
167
- ```
168
-
169
- If you update one of the tests, you can run it like so:
185
+ [ issues-list ] : https://github.com/mcmire/super_diff/issues
170
186
171
- ```
172
- bin/rspec spec/integration/...
173
- bin/rspec spec/unit/...
174
- ```
187
+ ## Contributing
175
188
176
- Finally, submit your PR and I'll take a look at it when I get a chance.
189
+ Any contributions to improve this library are welcome!
190
+ Please see the [ contributing] ( ./CONTRIBUTING.md ) document for more on how to do that.
177
191
178
192
## Compatibility
179
193
180
- ` super_diff ` is [ tested] [ travis ] to work with Ruby >= 2.4.x, RSpec 3.x, and
181
- Rails >= 5.x.
194
+ ` super_diff ` is [ tested] [ travis ] to work with
195
+ Ruby >= 2.4.x,
196
+ RSpec 3.x,
197
+ and Rails >= 5.x.
182
198
183
199
[ travis ] : http://travis-ci.org/mcmire/super_diff
184
200
185
201
## Inspiration/Thanks
186
202
187
- In developing this gem I made use of or was heavily inspired by these libraries:
203
+ In developing this gem
204
+ I made use of or was heavily inspired by these libraries:
188
205
189
- * [ Diff::LCS] [ diff-lcs ] , the library I started with in the [ original version of
190
- this gem] [ original-version ] (made in 2011!)
191
- * The pretty-printing algorithms and API within [ PrettyPrinter ] [ pretty-printer ]
192
- and [ AwesomePrint] [ awesome-print ] , from which I borrowed ideas to develop
193
- the [ inspectors] [ inspection-tree ] .
206
+ * [ Diff::LCS] [ diff-lcs ] ,
207
+ the library I started with in the [ original version of this gem] [ original-version ]
208
+ (made in 2011!)
209
+ * The pretty-printing algorithms and API within [ PrettyPrinter ] [ pretty-printer ] and [ AwesomePrint] [ awesome-print ] ,
210
+ from which I borrowed ideas to develop the [ inspectors] [ inspection-tree ] .
194
211
195
- Thank you so much !
212
+ Thank you to the authors of these libraries !
196
213
197
214
[ original-version ] : https://github.com/mcmire/super_diff/tree/old-master
198
215
[ diff-lcs ] : https://github.com/halostatue/diff-lcs
199
216
[ pretty-printer ] : https://github.com/ruby/ruby/tree/master/lib/prettyprint.rb
200
217
[ awesome-print ] : https://github.com/awesome-print/awesome_print
201
218
[ inspection-tree ] : https://github.com/mcmire/super_diff/blob/master/lib/super_diff/object_inspection/inspection_tree.rb
202
219
203
- ## Copyright /License
220
+ ## Author /License
204
221
205
- © 2018-2019 Elliot Winkler, released under the [ MIT license] ( LICENSE ) .
222
+ ` super_diff ` was created and is maintained by Elliot Winkler.
223
+ It is released under the [ MIT license] ( LICENSE ) .
0 commit comments