rspec_fixtures 0.7.0 → 0.7.1
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 +4 -4
- data/README.md +34 -2
- data/lib/rspec_fixtures/matchers/base.rb +1 -0
- data/lib/rspec_fixtures/matchers/output_fixture.rb +3 -3
- data/lib/rspec_fixtures/module_functions.rb +11 -0
- data/lib/rspec_fixtures/stream.rb +47 -0
- data/lib/rspec_fixtures/version.rb +1 -1
- data/lib/rspec_fixtures.rb +3 -1
- metadata +4 -3
- data/lib/rspec_fixtures/stream_capturer.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33762df05360b5ddd7eaa8e43e4447079d7835c54848678020971656d265d7b3
|
4
|
+
data.tar.gz: ae15eddc474dbe939e4c05093ebd386c0f0ec68ba5ce2b2b43b2e36ea9c46b68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4367dff06a97b7852e1e2a8e4d4f3eacecf620ecbba6e4c7422841442767719ea7130a3282cd94c9a6eb9b2748a3e11f6ad1800ada194db1f70b0337efbe0f9
|
7
|
+
data.tar.gz: 7998918e1c737a6d0777f334a8a358cf343e2473e23119465c380312bcaf8f80536fb46143bd446a3ad3b9be4c09886fa429d92ed26b74db52d6cdf91aeb20f6
|
data/README.md
CHANGED
@@ -99,7 +99,7 @@ Modifiers
|
|
99
99
|
Adding `diff(distance)` to either `match_fixture` or `output_fixture` will
|
100
100
|
change the matching behavior. Instead of expecting the strings to be exactly
|
101
101
|
the same, using `diff` compares the strings using the
|
102
|
-
[Levenshtein distance][
|
102
|
+
[Levenshtein distance][levenshtein] algorithm.
|
103
103
|
|
104
104
|
In the below example, we allow up to 5 characters to be different.
|
105
105
|
|
@@ -209,4 +209,36 @@ end
|
|
209
209
|
```
|
210
210
|
|
211
211
|
|
212
|
-
|
212
|
+
Advanced Usage Tips
|
213
|
+
--------------------------------------------------
|
214
|
+
|
215
|
+
In some cases, you might need to send output directly to the `RSpecFixture`
|
216
|
+
stream capturer.
|
217
|
+
|
218
|
+
An example use case, is when you are testing `Logger` output.
|
219
|
+
|
220
|
+
The `RSpecFixture#stdout` and `RSpecFixture#stderr` can be used as an
|
221
|
+
alternative to `$stdout` and `$stderr`. These methods both return the
|
222
|
+
`StringIO` object that is used by `RSpecFixtures` to capture the output.
|
223
|
+
|
224
|
+
For example, you can use this:
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
logger = Logger.new(RSpecFixtures.stdout)
|
228
|
+
```
|
229
|
+
|
230
|
+
as an alternative to this:
|
231
|
+
|
232
|
+
```
|
233
|
+
logger = Logger.new($stdout)
|
234
|
+
```
|
235
|
+
|
236
|
+
Contributing / Support
|
237
|
+
--------------------------------------------------
|
238
|
+
|
239
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
240
|
+
to contribute, feel free to [open an issue][issues].
|
241
|
+
|
242
|
+
|
243
|
+
[levenshtein]: https://en.wikipedia.org/wiki/Levenshtein_distance
|
244
|
+
[issues]: https://github.com/DannyBen/rspec_fixtures/issues
|
@@ -23,19 +23,19 @@ module RSpecFixtures
|
|
23
23
|
# expect{ stream }.to output_fixture(file).to_stdout
|
24
24
|
# This is the default, and only provided for completeness.
|
25
25
|
def to_stdout
|
26
|
-
@stream_capturer =
|
26
|
+
@stream_capturer = Stream::Stdout
|
27
27
|
self
|
28
28
|
end
|
29
29
|
|
30
30
|
# Adds chained matcher, to allow:
|
31
31
|
# expect{ stream }.to output_fixture(file).to_stderr
|
32
32
|
def to_stderr
|
33
|
-
@stream_capturer =
|
33
|
+
@stream_capturer = Stream::Stderr
|
34
34
|
self
|
35
35
|
end
|
36
36
|
|
37
37
|
def stream_capturer
|
38
|
-
@stream_capturer ||=
|
38
|
+
@stream_capturer ||= Stream::Stdout
|
39
39
|
end
|
40
40
|
|
41
41
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'strings-ansi'
|
2
|
+
|
3
|
+
module RSpecFixtures
|
4
|
+
# Capture stdout and stderr
|
5
|
+
#
|
6
|
+
# These methods are borrowed from rspec's built in matchers
|
7
|
+
# https://github.com/rspec/rspec-expectations/blob/add9b271ecb1d65f7da5bc8a9dd8c64d81d92303/lib/rspec/matchers/built_in/output.rb
|
8
|
+
module Stream
|
9
|
+
module Stdout
|
10
|
+
def self.capture(block)
|
11
|
+
captured_stream = RSpecFixtures.stdout
|
12
|
+
|
13
|
+
original_stream = $stdout
|
14
|
+
$stdout = captured_stream
|
15
|
+
|
16
|
+
block.call
|
17
|
+
|
18
|
+
result = captured_stream.string.dup
|
19
|
+
captured_stream.truncate 0
|
20
|
+
captured_stream.rewind
|
21
|
+
result
|
22
|
+
|
23
|
+
ensure
|
24
|
+
$stdout = original_stream
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module Stderr
|
29
|
+
def self.capture(block)
|
30
|
+
captured_stream = RSpecFixtures.stderr
|
31
|
+
|
32
|
+
original_stream = $stderr
|
33
|
+
$stderr = captured_stream
|
34
|
+
|
35
|
+
block.call
|
36
|
+
|
37
|
+
result = captured_stream.string.dup
|
38
|
+
captured_stream.truncate 0
|
39
|
+
captured_stream.rewind
|
40
|
+
result
|
41
|
+
|
42
|
+
ensure
|
43
|
+
$stderr = original_stream
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/rspec_fixtures.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rspec_fixtures/extensions/file'
|
2
2
|
|
3
|
-
require 'rspec_fixtures/
|
3
|
+
require 'rspec_fixtures/module_functions'
|
4
|
+
require 'rspec_fixtures/stream'
|
4
5
|
require 'rspec_fixtures/approval_handler'
|
5
6
|
require 'rspec_fixtures/matchers/base'
|
6
7
|
require 'rspec_fixtures/matchers/match_fixture'
|
@@ -8,3 +9,4 @@ require 'rspec_fixtures/matchers/output_fixture'
|
|
8
9
|
require 'rspec_fixtures/matchers/raise_fixture'
|
9
10
|
|
10
11
|
require 'rspec_fixtures/rspec_config'
|
12
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec_fixtures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -94,8 +94,9 @@ files:
|
|
94
94
|
- lib/rspec_fixtures/matchers/match_fixture.rb
|
95
95
|
- lib/rspec_fixtures/matchers/output_fixture.rb
|
96
96
|
- lib/rspec_fixtures/matchers/raise_fixture.rb
|
97
|
+
- lib/rspec_fixtures/module_functions.rb
|
97
98
|
- lib/rspec_fixtures/rspec_config.rb
|
98
|
-
- lib/rspec_fixtures/
|
99
|
+
- lib/rspec_fixtures/stream.rb
|
99
100
|
- lib/rspec_fixtures/version.rb
|
100
101
|
homepage: https://github.com/DannyBen/rspec_fixtures
|
101
102
|
licenses:
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'strings-ansi'
|
2
|
-
|
3
|
-
module RSpecFixtures
|
4
|
-
# Capture stdout and stderr
|
5
|
-
#
|
6
|
-
# These methods are borrowed from rspec's built in matchers
|
7
|
-
# https://github.com/rspec/rspec-expectations/blob/add9b271ecb1d65f7da5bc8a9dd8c64d81d92303/lib/rspec/matchers/built_in/output.rb
|
8
|
-
module CaptureStdout
|
9
|
-
def self.capture(block)
|
10
|
-
captured_stream = StringIO.new
|
11
|
-
|
12
|
-
original_stream = $stdout
|
13
|
-
$stdout = captured_stream
|
14
|
-
|
15
|
-
block.call
|
16
|
-
|
17
|
-
captured_stream.string
|
18
|
-
|
19
|
-
ensure
|
20
|
-
$stdout = original_stream
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module CaptureStderr
|
25
|
-
def self.capture(block)
|
26
|
-
captured_stream = StringIO.new
|
27
|
-
|
28
|
-
original_stream = $stderr
|
29
|
-
$stderr = captured_stream
|
30
|
-
|
31
|
-
block.call
|
32
|
-
|
33
|
-
captured_stream.string
|
34
|
-
|
35
|
-
ensure
|
36
|
-
$stderr = original_stream
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|