rspec_fixtures 0.7.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33762df05360b5ddd7eaa8e43e4447079d7835c54848678020971656d265d7b3
4
- data.tar.gz: ae15eddc474dbe939e4c05093ebd386c0f0ec68ba5ce2b2b43b2e36ea9c46b68
3
+ metadata.gz: 98900a115a9524e293d62e5314630d7b892afb84bc506257683c0d689c33ed82
4
+ data.tar.gz: 1d5286deaed5cf509183e90a320b323e9af4759c8acd1f013de46a8e0cb25e2c
5
5
  SHA512:
6
- metadata.gz: c4367dff06a97b7852e1e2a8e4d4f3eacecf620ecbba6e4c7422841442767719ea7130a3282cd94c9a6eb9b2748a3e11f6ad1800ada194db1f70b0337efbe0f9
7
- data.tar.gz: 7998918e1c737a6d0777f334a8a358cf343e2473e23119465c380312bcaf8f80536fb46143bd446a3ad3b9be4c09886fa429d92ed26b74db52d6cdf91aeb20f6
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
@@ -6,5 +6,6 @@ if defined? RSpec
6
6
  config.add_setting :interactive_fixtures, default: !ENV['CI']
7
7
  config.add_setting :auto_approve, default: ENV['AUTO_APPROVE']
8
8
  config.add_setting :strip_ansi_escape, default: false
9
+ config.add_setting :before_approval, default: nil
9
10
  end
10
11
  end
@@ -8,39 +8,33 @@ module RSpecFixtures
8
8
  module Stream
9
9
  module Stdout
10
10
  def self.capture(block)
11
- captured_stream = RSpecFixtures.stdout
11
+ RSpecFixtures.stdout.truncate 0
12
+ RSpecFixtures.stdout.rewind
12
13
 
13
14
  original_stream = $stdout
14
- $stdout = captured_stream
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
- captured_stream = RSpecFixtures.stderr
27
+ RSpecFixtures.stderr.truncate 0
28
+ RSpecFixtures.stderr.rewind
31
29
 
32
30
  original_stream = $stderr
33
- $stderr = captured_stream
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
@@ -1,3 +1,3 @@
1
1
  module RSpecFixtures
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit