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 Ruby gem that intelligently displays the differences between two
11
- data structures of any type.
10
+ SuperDiff is a gem that hooks into RSpec to intelligently display the
11
+ differences between two data structures of any type.
12
12
13
13
📢 ** [ See what's changed in the latest version (0.2.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 replace RSpec's built-in diffing
20
- capabilities. Sometimes, whenever you use a matcher such as ` eq ` , ` match ` ,
21
- ` include ` , or ` have_attributes ` , you will get a diff of the two data structures
22
- you are trying to match against. This is really helpful for strings, but not so
23
- helpful for other, more "real world" kinds of values, such as arrays, hashes,
24
- and full-scale objects. The reason this doesn't work is because [ all RSpec does
25
- is run your ` expected ` and ` actual ` values through Ruby's PrettyPrinter
26
- library] [ rspec-differ-fail ] and then perform a diff of these strings.
19
+ The primary motivation behind this gem is to vastly improve upon RSpec's
20
+ built-in diffing capabilities.
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.
32
+
33
+ [ rspec-differ-fail ] : https://github.com/rspec/rspec-support/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
27
34
28
35
For instance, let's say you wanted to compare these two hashes:
29
36
@@ -75,20 +82,16 @@ If, somewhere in a test, you were to say:
75
82
expect(actual).to eq(expected)
76
83
```
77
84
78
- You would get output that looks like:
85
+ You would get output that looks like this :
79
86
80
87
![ Before super_diff] ( doc/before_super_diff.png )
81
88
82
- Not great.
83
-
84
- This library provides a diff engine that knows how to figure out the differences
85
- between any two data structures and display them in a sensible way. Using the
86
- example above, you'd get this instead:
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:
87
92
88
93
![ After super_diff] ( doc/after_super_diff.png )
89
94
90
- [ rspec-differ-fail ] : https://github.com/rspec/rspec-support/blob/c69a231d7369dd165ad7ce4742e1a2e21e3462b5/lib/rspec/support/differ.rb#L178
91
-
92
95
## Installation
93
96
94
97
Want to try out this gem for yourself? As with most development-related gems,
@@ -131,7 +134,7 @@ You're done!
131
134
As capable as this library is, it doesn't know how to deal with every kind of
132
135
object out there. You might find it necessary to instruct the gem on how to diff
133
136
your object. To do this, you can use a configuration block. Simply add this to
134
- your test helper file (either ` rails_helper ` or ` spec_helper ` ):
137
+ your test helper file (` rails_helper ` or ` spec_helper ` ):
135
138
136
139
``` ruby
137
140
SuperDiff ::RSpec .configure do |config |
@@ -153,21 +156,21 @@ If you'd like to submit a PR instead, here's how to get started. First, fork
153
156
this repo. Then, when you've cloned your fork, run:
154
157
155
158
```
156
- bundle install
159
+ bin/setup
157
160
```
158
161
159
162
This will install various dependencies. After this, you can run all of the
160
- tests:
163
+ tests:
161
164
162
165
```
163
166
bundle exec rake
164
167
```
165
168
166
- Or a single test :
169
+ If you update one of the tests, you can run it like so :
167
170
168
171
```
169
- bundle exec rspec spec/acceptance /...
170
- bundle exec rspec spec/unit/...
172
+ bin/ rspec spec/integration /...
173
+ bin/ rspec spec/unit/...
171
174
```
172
175
173
176
Finally, submit your PR and I'll take a look at it when I get a chance.
0 commit comments