rspec_fixtures 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/lib/rspec_fixtures/matchers/base.rb +6 -0
- data/lib/rspec_fixtures/rspec_config.rb +1 -0
- data/lib/rspec_fixtures/stream.rb +10 -16
- data/lib/rspec_fixtures/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98900a115a9524e293d62e5314630d7b892afb84bc506257683c0d689c33ed82
|
4
|
+
data.tar.gz: 1d5286deaed5cf509183e90a320b323e9af4759c8acd1f013de46a8e0cb25e2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0313b2a363c52302091ec8b6fd22f9356924cf5f279912265a6da87baca143c42078901f479d32337be8a3d6e58662790fab011b84f00711f8676ecd947f350d
|
7
|
+
data.tar.gz: d2acf4a46bd929b5e5857c13596c89015ed574b0566ad15f6080842dc1511aca8d4917026fb203006ee2d41ae14e4dd9248a2214ee8e81cfe5a4c4afc98367e0
|
data/README.md
CHANGED
@@ -197,6 +197,7 @@ delete the fixtures folder, and run the specs again with:
|
|
197
197
|
$ AUTO_APPROVE=1 rspec
|
198
198
|
```
|
199
199
|
|
200
|
+
|
200
201
|
### `strip_ansi_escape`
|
201
202
|
|
202
203
|
In case your output strings contain ANSI escape codes that you wish to avoid
|
@@ -209,6 +210,24 @@ end
|
|
209
210
|
```
|
210
211
|
|
211
212
|
|
213
|
+
### `before_approval`
|
214
|
+
|
215
|
+
In case you need to alter the actual output globally, you can provide the
|
216
|
+
`before_approval` option with a proc. The proc will receive the actual
|
217
|
+
output - similarly to the `before` modifier - and is expectedd to return
|
218
|
+
a modified actual string.
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
RSpec.configure do |config|
|
222
|
+
config.before_approval = ->(actual) do
|
223
|
+
# return the actual string, without IP addresses
|
224
|
+
actual.gsub(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/, '[IP REMOVED]')
|
225
|
+
end
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
|
230
|
+
|
212
231
|
Advanced Usage Tips
|
213
232
|
--------------------------------------------------
|
214
233
|
|
@@ -113,6 +113,8 @@ module RSpecFixtures
|
|
113
113
|
# Do the actual test.
|
114
114
|
# - If .before() was used, we foreward the actual output to the
|
115
115
|
# proc for processing first.
|
116
|
+
# - If before_approval proc was configured, forward the acual output
|
117
|
+
# to the proc for processing.
|
116
118
|
# - If .diff() was used, then distance will be set and then
|
117
119
|
# we "levenshtein it".
|
118
120
|
# - Otherwise, compare with ==
|
@@ -122,6 +124,10 @@ module RSpecFixtures
|
|
122
124
|
@actual = proc.call actual
|
123
125
|
end
|
124
126
|
end
|
127
|
+
|
128
|
+
if RSpec.configuration.before_approval.is_a? Proc
|
129
|
+
@actual = RSpec.configuration.before_approval.call actual
|
130
|
+
end
|
125
131
|
|
126
132
|
if distance
|
127
133
|
@actual_distance = String::Similarity.levenshtein_distance expected, actual
|
@@ -8,39 +8,33 @@ module RSpecFixtures
|
|
8
8
|
module Stream
|
9
9
|
module Stdout
|
10
10
|
def self.capture(block)
|
11
|
-
|
11
|
+
RSpecFixtures.stdout.truncate 0
|
12
|
+
RSpecFixtures.stdout.rewind
|
12
13
|
|
13
14
|
original_stream = $stdout
|
14
|
-
$stdout =
|
15
|
-
|
15
|
+
$stdout = RSpecFixtures.stdout
|
16
16
|
block.call
|
17
|
-
|
18
|
-
result = captured_stream.string.dup
|
19
|
-
captured_stream.truncate 0
|
20
|
-
captured_stream.rewind
|
21
|
-
result
|
17
|
+
RSpecFixtures.stdout.string.dup
|
22
18
|
|
23
19
|
ensure
|
24
20
|
$stdout = original_stream
|
21
|
+
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
25
|
module Stderr
|
29
26
|
def self.capture(block)
|
30
|
-
|
27
|
+
RSpecFixtures.stderr.truncate 0
|
28
|
+
RSpecFixtures.stderr.rewind
|
31
29
|
|
32
30
|
original_stream = $stderr
|
33
|
-
$stderr =
|
34
|
-
|
31
|
+
$stderr = RSpecFixtures.stderr
|
35
32
|
block.call
|
33
|
+
RSpecFixtures.stderr.string.dup
|
36
34
|
|
37
|
-
result = captured_stream.string.dup
|
38
|
-
captured_stream.truncate 0
|
39
|
-
captured_stream.rewind
|
40
|
-
result
|
41
|
-
|
42
35
|
ensure
|
43
36
|
$stderr = original_stream
|
37
|
+
|
44
38
|
end
|
45
39
|
end
|
46
40
|
end
|