rspec_fixtures 0.5.1 → 0.7.5
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 +151 -30
- data/lib/rspec_fixtures/approval_handler.rb +6 -2
- data/lib/rspec_fixtures/matchers/base.rb +50 -4
- data/lib/rspec_fixtures/matchers/output_fixture.rb +4 -4
- data/lib/rspec_fixtures/matchers/raise_fixture.rb +30 -0
- data/lib/rspec_fixtures/module_functions.rb +11 -0
- data/lib/rspec_fixtures/rspec_config.rb +7 -1
- data/lib/rspec_fixtures/stream.rb +41 -0
- data/lib/rspec_fixtures/version.rb +1 -1
- data/lib/rspec_fixtures.rb +4 -1
- metadata +16 -85
- data/lib/rspec_fixtures/stream_capturer.rb +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb8f8b75d70850e9a14951c5d0122ea3fe8bebf93a44222280a718d5feba0141
|
|
4
|
+
data.tar.gz: 6ae24884be39d133d86a5a752c04127918fca26cf54dc31b652d13419a4c1b26
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e16667109c5485fae7b6a6025020727300cfed32df7e3b12beb22b75e8a64686dab130b942b4590666798189d700fb1868d76cc13ada4a7b6d1d059cf2f8518
|
|
7
|
+
data.tar.gz: 748d45d8ad6de2f58639f9e2a9e9116d997e93dceef9addec83533a90b2a075cd38b01e619098c1a51d5205f4c170128ed2e556cc7217b9938d99ed79e00c94a
|
data/README.md
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
RSpec Fixtures
|
|
2
|
-
==================================================
|
|
1
|
+
# RSpec Fixtures
|
|
3
2
|
|
|
4
3
|
[](https://badge.fury.io/rb/rspec_fixtures)
|
|
5
|
-
[](https://github.com/DannyBen/rspec_fixtures/actions?query=workflow%3ATest)
|
|
6
5
|
[](https://codeclimate.com/github/DannyBen/rspec_fixtures/maintainability)
|
|
7
|
-
[](https://codeclimate.com/github/DannyBen/rspec_fixtures/test_coverage)
|
|
8
6
|
|
|
9
7
|
---
|
|
10
8
|
|
|
@@ -14,14 +12,11 @@ content.
|
|
|
14
12
|
This is a *"What You See is What You Test"* for your specs, because
|
|
15
13
|
*a Fixture is worth a thousand Mocks*... (too much?...)
|
|
16
14
|
|
|
17
|
-

|
|
18
16
|
|
|
19
17
|
---
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Install
|
|
24
|
-
--------------------------------------------------
|
|
19
|
+
## Install
|
|
25
20
|
|
|
26
21
|
```
|
|
27
22
|
$ gem install rspec_fixtures
|
|
@@ -33,10 +28,7 @@ Or with bundler:
|
|
|
33
28
|
gem 'rspec_fixtures'
|
|
34
29
|
```
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Usage
|
|
39
|
-
--------------------------------------------------
|
|
31
|
+
## Usage
|
|
40
32
|
|
|
41
33
|
Require the gem in your spec helper:
|
|
42
34
|
|
|
@@ -55,10 +47,7 @@ describe 'ls' do
|
|
|
55
47
|
end
|
|
56
48
|
```
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Matchers
|
|
61
|
-
--------------------------------------------------
|
|
50
|
+
## Matchers
|
|
62
51
|
|
|
63
52
|
### `match_fixture` - Compare Strings
|
|
64
53
|
|
|
@@ -74,38 +63,84 @@ expect('some string').to match_fixture('fixture_filename')
|
|
|
74
63
|
Compare an output (stdout or stderr) with a pre-approved fixture.
|
|
75
64
|
|
|
76
65
|
```ruby
|
|
77
|
-
expect{ puts "hello" }.to output_fixture('fixture_filename')
|
|
78
|
-
expect{ puts "hello" }.to output_fixture('fixture_filename').to_stdout
|
|
79
|
-
expect{ $stderr.puts "hello" }.to output_fixture('fixture_filename').to_stderr
|
|
66
|
+
expect { puts "hello" }.to output_fixture('fixture_filename')
|
|
67
|
+
expect { puts "hello" }.to output_fixture('fixture_filename').to_stdout
|
|
68
|
+
expect { $stderr.puts "hello" }.to output_fixture('fixture_filename').to_stderr
|
|
80
69
|
|
|
81
70
|
# The first two are the same, as the default stream is stdout.
|
|
82
71
|
```
|
|
83
72
|
|
|
84
73
|
|
|
85
|
-
### `
|
|
74
|
+
### `raise_fixture` - Compare raised exceptions
|
|
75
|
+
|
|
76
|
+
Compare a raised exception with a pre-approved fixture.
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
expect { raise 'some error' }.to raise_fixture('fixture_filename')
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Modifiers
|
|
83
|
+
|
|
84
|
+
### `diff` - String similarity
|
|
86
85
|
|
|
87
86
|
Adding `diff(distance)` to either `match_fixture` or `output_fixture` will
|
|
88
87
|
change the matching behavior. Instead of expecting the strings to be exactly
|
|
89
88
|
the same, using `diff` compares the strings using the
|
|
90
|
-
[Levenshtein distance][
|
|
89
|
+
[Levenshtein distance][levenshtein] algorithm.
|
|
91
90
|
|
|
92
91
|
In the below example, we allow up to 5 characters to be different.
|
|
93
92
|
|
|
94
93
|
```ruby
|
|
95
|
-
expect('some string').to match_fixture('fixture_filename').diff(5)
|
|
96
|
-
expect{ puts 'some string' }.to output_fixture('fixture_filename').diff(5)
|
|
94
|
+
expect ('some string').to match_fixture('fixture_filename').diff(5)
|
|
95
|
+
expect { puts 'some string' }.to output_fixture('fixture_filename').diff(5)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `except` - Exclude by regular expression
|
|
99
|
+
|
|
100
|
+
Adding `except(regex)` to either `match_fixture` or `output_fixture` will
|
|
101
|
+
modify the string under test before running. By default, the regular
|
|
102
|
+
expression will be replaced with `...`.
|
|
103
|
+
|
|
104
|
+
In the below example, we ignore the full path of the file.
|
|
105
|
+
|
|
106
|
+
```ruby
|
|
107
|
+
expect('path: /path/to/file').to match_fixture('fixture_filename').except(/path: .*file/)
|
|
97
108
|
```
|
|
98
109
|
|
|
110
|
+
You may provide a second argument, which will be used as an alternative
|
|
111
|
+
replace string:
|
|
99
112
|
|
|
113
|
+
In the below example, all time strings will be replaced with `HH:MM`:
|
|
100
114
|
|
|
101
|
-
|
|
102
|
-
|
|
115
|
+
```ruby
|
|
116
|
+
expect('22:30').to match_fixture('fixture_filename').except(/\d2:\d2/, 'HH:MM')
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `before` - Alter the string before testing
|
|
120
|
+
|
|
121
|
+
The `before(proc)` method is a low level method and should normally not be
|
|
122
|
+
used directly (as it is used by the `except` modifier).
|
|
123
|
+
|
|
124
|
+
Adding `before(proc)` to either `match_fixture` or `output_fixture` will
|
|
125
|
+
call the block and supply the actual string. The proc is expected to return
|
|
126
|
+
the new actual string.
|
|
127
|
+
|
|
128
|
+
In the below example, we replace all email addresses in a string.
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
expect('hello rspec@fixtures.com').to match_fixture('fixture_filename').before ->(actual) do
|
|
132
|
+
actual.gsub /\w+@\w+\.\w+/, 'some@email.com'
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Configuration
|
|
103
138
|
|
|
104
139
|
### `interactive_fixtures`
|
|
105
140
|
|
|
106
141
|
By default, interactive approvals are enabled in any environment that
|
|
107
|
-
does not define the `CI`
|
|
108
|
-
adding this to your `spec_helper`
|
|
142
|
+
does not define the `CI` or the `GITHUB_ACTIONS` environment variables.
|
|
143
|
+
You can change this by adding this to your `spec_helper`
|
|
109
144
|
|
|
110
145
|
```ruby
|
|
111
146
|
RSpec.configure do |config|
|
|
@@ -113,7 +148,6 @@ RSpec.configure do |config|
|
|
|
113
148
|
end
|
|
114
149
|
```
|
|
115
150
|
|
|
116
|
-
|
|
117
151
|
### `fixtures_path`
|
|
118
152
|
|
|
119
153
|
By default, fixtures are stored in `spec/fixtures`. To change the path,
|
|
@@ -125,5 +159,92 @@ RSpec.configure do |config|
|
|
|
125
159
|
end
|
|
126
160
|
```
|
|
127
161
|
|
|
162
|
+
### `auto_approve`
|
|
163
|
+
|
|
164
|
+
If you wish to automatically approve all new or changed fixtures, you can
|
|
165
|
+
set the `auto_approve` configuration option to `true`. By default,
|
|
166
|
+
auto approval is enabled if the environment variable `AUTO_APPROVE` is set.
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
RSpec.configure do |config|
|
|
170
|
+
config.auto_approve = true # or any logic
|
|
171
|
+
end
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
This feature is intended to help clean up the fixtures folder from old, no
|
|
175
|
+
longer used files. Simply run the specs once, to ensure they all oass,
|
|
176
|
+
delete the fixtures folder, and run the specs again with:
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
$ AUTO_APPROVE=1 rspec
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### `strip_ansi_escape`
|
|
183
|
+
|
|
184
|
+
In case your output strings contain ANSI escape codes that you wish to avoid
|
|
185
|
+
storing in your fixtures, you can set the `strip_ansi_escape` to `true`.
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
RSpec.configure do |config|
|
|
189
|
+
config.strip_ansi_escape = true
|
|
190
|
+
end
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `before_approval`
|
|
194
|
+
|
|
195
|
+
In case you need to alter the actual output globally, you can provide the
|
|
196
|
+
`before_approval` option with a proc. The proc will receive the actual
|
|
197
|
+
output - similarly to the `before` modifier - and is expectedd to return
|
|
198
|
+
a modified actual string.
|
|
199
|
+
|
|
200
|
+
```ruby
|
|
201
|
+
RSpec.configure do |config|
|
|
202
|
+
config.before_approval = ->(actual) do
|
|
203
|
+
# return the actual string, without IP addresses
|
|
204
|
+
actual.gsub(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/, '[IP REMOVED]')
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Advanced Usage Tips
|
|
210
|
+
|
|
211
|
+
### Sending output directly to RSpecFixtures
|
|
212
|
+
|
|
213
|
+
In some cases, you might need to send output directly to the `RSpecFixture`
|
|
214
|
+
stream capturer.
|
|
215
|
+
|
|
216
|
+
An example use case, is when you are testing `Logger` output.
|
|
217
|
+
|
|
218
|
+
The `RSpecFixture#stdout` and `RSpecFixture#stderr` can be used as an
|
|
219
|
+
alternative to `$stdout` and `$stderr`. These methods both return the
|
|
220
|
+
`StringIO` object that is used by `RSpecFixtures` to capture the output.
|
|
221
|
+
|
|
222
|
+
For example, you can use this:
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
225
|
+
logger = Logger.new(RSpecFixtures.stdout)
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
as an alternative to this:
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
logger = Logger.new($stdout)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Consistent terminal width
|
|
235
|
+
|
|
236
|
+
In case you are testing standard output with long lines, you may encounter inconsistencies when testing on different hosts, with varying terminal width. In order to ensure consistent output to stdout, you may want to set a known terminal size in your `spec_helper`:
|
|
237
|
+
|
|
238
|
+
```ruby
|
|
239
|
+
ENV['COLUMNS'] = '80'
|
|
240
|
+
ENV['LINES'] = '24'
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Contributing / Support
|
|
244
|
+
|
|
245
|
+
If you experience any issue, have a question or a suggestion, or if you wish
|
|
246
|
+
to contribute, feel free to [open an issue][issues].
|
|
247
|
+
|
|
128
248
|
|
|
129
|
-
[
|
|
249
|
+
[levenshtein]: https://en.wikipedia.org/wiki/Levenshtein_distance
|
|
250
|
+
[issues]: https://github.com/DannyBen/rspec_fixtures/issues
|
|
@@ -23,7 +23,7 @@ module RSpecFixtures
|
|
|
23
23
|
private
|
|
24
24
|
|
|
25
25
|
def prompt_user
|
|
26
|
-
response = get_response
|
|
26
|
+
response = auto_approve? ? :approve : get_response
|
|
27
27
|
|
|
28
28
|
case response
|
|
29
29
|
|
|
@@ -40,8 +40,12 @@ module RSpecFixtures
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
def auto_approve?
|
|
44
|
+
RSpec.configuration.auto_approve
|
|
45
|
+
end
|
|
46
|
+
|
|
43
47
|
def get_response
|
|
44
|
-
prompt.select "Please Choose:", menu_options, marker: '>'
|
|
48
|
+
prompt.select "Please Choose:", menu_options, symbols: { marker: '>' }
|
|
45
49
|
rescue TTY::Reader::InputInterrupt
|
|
46
50
|
# :nocov:
|
|
47
51
|
return :reject
|
|
@@ -6,6 +6,7 @@ module RSpecFixtures
|
|
|
6
6
|
attr_reader :fixture_name, :actual, :distance, :actual_distance
|
|
7
7
|
|
|
8
8
|
def initialize(fixture_name=nil)
|
|
9
|
+
@before = nil
|
|
9
10
|
@fixture_name = fixture_name
|
|
10
11
|
end
|
|
11
12
|
|
|
@@ -14,6 +15,7 @@ module RSpecFixtures
|
|
|
14
15
|
@actual ||= actual
|
|
15
16
|
return false if @actual.empty?
|
|
16
17
|
|
|
18
|
+
@actual = sanitize @actual
|
|
17
19
|
success = strings_match?
|
|
18
20
|
|
|
19
21
|
if success or !interactive?
|
|
@@ -23,7 +25,7 @@ module RSpecFixtures
|
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
27
|
|
|
26
|
-
#
|
|
28
|
+
# Enables the ability to do something like:
|
|
27
29
|
# `expect(string).to match_fixture(file).diff(10)
|
|
28
30
|
# The distance argument is the max allowed Levenshtein Distance.
|
|
29
31
|
def diff(distance)
|
|
@@ -31,6 +33,23 @@ module RSpecFixtures
|
|
|
31
33
|
self
|
|
32
34
|
end
|
|
33
35
|
|
|
36
|
+
# Enables the ability to do something like:
|
|
37
|
+
# `expect(string).to match_fixture(file).except(/\d+/)
|
|
38
|
+
def except(regex, replace = '...')
|
|
39
|
+
before ->(str) do
|
|
40
|
+
str.gsub regex, replace
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Enables the ability to adjust the actual string before checking
|
|
45
|
+
# for matches:
|
|
46
|
+
# `expect(a).to match_fixture(f).before ->(actual) { actual.gsub /one/, 'two' }`
|
|
47
|
+
def before(proc)
|
|
48
|
+
@before ||= []
|
|
49
|
+
@before << proc
|
|
50
|
+
self
|
|
51
|
+
end
|
|
52
|
+
|
|
34
53
|
# Returns the expected value, from a fixture file
|
|
35
54
|
def expected
|
|
36
55
|
@expected ||= expected!
|
|
@@ -54,6 +73,12 @@ module RSpecFixtures
|
|
|
54
73
|
true
|
|
55
74
|
end
|
|
56
75
|
|
|
76
|
+
# Returns true if RSpec is configured to sanitize (remove ANSI escape
|
|
77
|
+
# codes) from the actual strings before proceeeding to comparing them.
|
|
78
|
+
def sanitize?
|
|
79
|
+
RSpec.configuration.strip_ansi_escape
|
|
80
|
+
end
|
|
81
|
+
|
|
57
82
|
# Returns true if RSpec is configured to allow interactivity.
|
|
58
83
|
# By default, interactivity is enabled unless the environment
|
|
59
84
|
# variable `CI` is set.
|
|
@@ -72,7 +97,7 @@ module RSpecFixtures
|
|
|
72
97
|
"#{fixtures_dir}/#{fixture_name}"
|
|
73
98
|
end
|
|
74
99
|
|
|
75
|
-
|
|
100
|
+
protected
|
|
76
101
|
|
|
77
102
|
# Asks for user approval. Used by child classes.
|
|
78
103
|
def approve_fixture
|
|
@@ -85,9 +110,25 @@ module RSpecFixtures
|
|
|
85
110
|
File.exist?(fixture_file) ? File.read(fixture_file) : ''
|
|
86
111
|
end
|
|
87
112
|
|
|
88
|
-
# Do the actual test.
|
|
89
|
-
#
|
|
113
|
+
# Do the actual test.
|
|
114
|
+
# - If .before() was used, we foreward the actual output to the
|
|
115
|
+
# proc for processing first.
|
|
116
|
+
# - If before_approval proc was configured, forward the acual output
|
|
117
|
+
# to the proc for processing.
|
|
118
|
+
# - If .diff() was used, then distance will be set and then
|
|
119
|
+
# we "levenshtein it".
|
|
120
|
+
# - Otherwise, compare with ==
|
|
90
121
|
def strings_match?
|
|
122
|
+
if @before
|
|
123
|
+
@before.each do |proc|
|
|
124
|
+
@actual = proc.call actual
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
if RSpec.configuration.before_approval.is_a? Proc
|
|
129
|
+
@actual = RSpec.configuration.before_approval.call actual
|
|
130
|
+
end
|
|
131
|
+
|
|
91
132
|
if distance
|
|
92
133
|
@actual_distance = String::Similarity.levenshtein_distance expected, actual
|
|
93
134
|
@actual_distance <= distance
|
|
@@ -96,6 +137,11 @@ module RSpecFixtures
|
|
|
96
137
|
end
|
|
97
138
|
end
|
|
98
139
|
|
|
140
|
+
# Returns the input string stripped of ANSI escape codes if the
|
|
141
|
+
# strip_ansi_escape configuration setting was set to true
|
|
142
|
+
def sanitize(string)
|
|
143
|
+
sanitize? ? Strings::ANSI.sanitize(string) : string
|
|
144
|
+
end
|
|
99
145
|
end
|
|
100
146
|
|
|
101
147
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module RSpecFixtures
|
|
2
2
|
module Matchers
|
|
3
3
|
# Adds the matcher to RSpec:
|
|
4
|
-
# `expect{ stream }.to output_fixture(file)`
|
|
4
|
+
# `expect { stream }.to output_fixture(file)`
|
|
5
5
|
def output_fixture(expected)
|
|
6
6
|
OutputFixture.new expected
|
|
7
7
|
end
|
|
@@ -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,30 @@
|
|
|
1
|
+
module RSpecFixtures
|
|
2
|
+
module Matchers
|
|
3
|
+
# Adds the matcher to RSpec:
|
|
4
|
+
# `expect { something_that_errors }.to raise_fixture(file)`
|
|
5
|
+
def raise_fixture(expected)
|
|
6
|
+
RaiseFixture.new expected
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class RaiseFixture < Base
|
|
10
|
+
# Called by RSpec
|
|
11
|
+
def matches?(block)
|
|
12
|
+
return false unless block.is_a? Proc
|
|
13
|
+
@actual = 'Nothing raised'
|
|
14
|
+
|
|
15
|
+
begin
|
|
16
|
+
block.call
|
|
17
|
+
rescue => e
|
|
18
|
+
@actual = e.inspect
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Lets RSpec know that this matcher requires a block.
|
|
25
|
+
def supports_block_expectations?
|
|
26
|
+
true
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
# Add our custom matchers and configuration options to RSpec
|
|
2
2
|
if defined? RSpec
|
|
3
|
+
# Fix for rails
|
|
4
|
+
require 'rspec/core' unless RSpec.respond_to? :configure
|
|
5
|
+
|
|
3
6
|
RSpec.configure do |config|
|
|
4
7
|
config.include RSpecFixtures::Matchers
|
|
5
8
|
config.add_setting :fixtures_path, default: File.expand_path('spec/fixtures')
|
|
6
|
-
config.add_setting :interactive_fixtures, default: !ENV['CI']
|
|
9
|
+
config.add_setting :interactive_fixtures, default: (!ENV['CI'] and !ENV['GITHUB_ACTIONS'])
|
|
10
|
+
config.add_setting :auto_approve, default: ENV['AUTO_APPROVE']
|
|
11
|
+
config.add_setting :strip_ansi_escape, default: false
|
|
12
|
+
config.add_setting :before_approval, default: nil
|
|
7
13
|
end
|
|
8
14
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
RSpecFixtures.stdout.truncate 0
|
|
12
|
+
RSpecFixtures.stdout.rewind
|
|
13
|
+
|
|
14
|
+
original_stream = $stdout
|
|
15
|
+
$stdout = RSpecFixtures.stdout
|
|
16
|
+
block.call
|
|
17
|
+
RSpecFixtures.stdout.string.dup
|
|
18
|
+
|
|
19
|
+
ensure
|
|
20
|
+
$stdout = original_stream
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module Stderr
|
|
26
|
+
def self.capture(block)
|
|
27
|
+
RSpecFixtures.stderr.truncate 0
|
|
28
|
+
RSpecFixtures.stderr.rewind
|
|
29
|
+
|
|
30
|
+
original_stream = $stderr
|
|
31
|
+
$stderr = RSpecFixtures.stderr
|
|
32
|
+
block.call
|
|
33
|
+
RSpecFixtures.stderr.string.dup
|
|
34
|
+
|
|
35
|
+
ensure
|
|
36
|
+
$stderr = original_stream
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
data/lib/rspec_fixtures.rb
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
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'
|
|
7
8
|
require 'rspec_fixtures/matchers/output_fixture'
|
|
9
|
+
require 'rspec_fixtures/matchers/raise_fixture'
|
|
8
10
|
|
|
9
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.5
|
|
4
|
+
version: 0.7.5
|
|
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:
|
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colsole
|
|
@@ -44,112 +44,42 @@ dependencies:
|
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '3.
|
|
47
|
+
version: '3.3'
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '3.
|
|
54
|
+
version: '3.3'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: tty-prompt
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0.
|
|
61
|
+
version: '0.19'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0.
|
|
68
|
+
version: '0.19'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
70
|
+
name: strings-ansi
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '
|
|
76
|
-
type: :
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '3.7'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: runfile
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: '0.9'
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - "~>"
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: '0.9'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: runfile-tasks
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - "~>"
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '0.4'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - "~>"
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0.4'
|
|
111
|
-
- !ruby/object:Gem::Dependency
|
|
112
|
-
name: byebug
|
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
|
114
|
-
requirements:
|
|
115
|
-
- - "~>"
|
|
116
|
-
- !ruby/object:Gem::Version
|
|
117
|
-
version: '9.0'
|
|
118
|
-
type: :development
|
|
119
|
-
prerelease: false
|
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
requirements:
|
|
122
|
-
- - "~>"
|
|
123
|
-
- !ruby/object:Gem::Version
|
|
124
|
-
version: '9.0'
|
|
125
|
-
- !ruby/object:Gem::Dependency
|
|
126
|
-
name: simplecov
|
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
|
128
|
-
requirements:
|
|
129
|
-
- - "~>"
|
|
130
|
-
- !ruby/object:Gem::Version
|
|
131
|
-
version: '0.14'
|
|
132
|
-
type: :development
|
|
133
|
-
prerelease: false
|
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
-
requirements:
|
|
136
|
-
- - "~>"
|
|
137
|
-
- !ruby/object:Gem::Version
|
|
138
|
-
version: '0.14'
|
|
139
|
-
- !ruby/object:Gem::Dependency
|
|
140
|
-
name: yard
|
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
|
142
|
-
requirements:
|
|
143
|
-
- - "~>"
|
|
144
|
-
- !ruby/object:Gem::Version
|
|
145
|
-
version: '0.9'
|
|
146
|
-
type: :development
|
|
75
|
+
version: '0.1'
|
|
76
|
+
type: :runtime
|
|
147
77
|
prerelease: false
|
|
148
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
79
|
requirements:
|
|
150
80
|
- - "~>"
|
|
151
81
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: '0.
|
|
82
|
+
version: '0.1'
|
|
153
83
|
description: Automatic interactive fixtures for rspec
|
|
154
84
|
email: db@dannyben.com
|
|
155
85
|
executables: []
|
|
@@ -163,14 +93,16 @@ files:
|
|
|
163
93
|
- lib/rspec_fixtures/matchers/base.rb
|
|
164
94
|
- lib/rspec_fixtures/matchers/match_fixture.rb
|
|
165
95
|
- lib/rspec_fixtures/matchers/output_fixture.rb
|
|
96
|
+
- lib/rspec_fixtures/matchers/raise_fixture.rb
|
|
97
|
+
- lib/rspec_fixtures/module_functions.rb
|
|
166
98
|
- lib/rspec_fixtures/rspec_config.rb
|
|
167
|
-
- lib/rspec_fixtures/
|
|
99
|
+
- lib/rspec_fixtures/stream.rb
|
|
168
100
|
- lib/rspec_fixtures/version.rb
|
|
169
101
|
homepage: https://github.com/DannyBen/rspec_fixtures
|
|
170
102
|
licenses:
|
|
171
103
|
- MIT
|
|
172
104
|
metadata: {}
|
|
173
|
-
post_install_message:
|
|
105
|
+
post_install_message: 'Note: rspec_fixtures is now rspec_approvals, update your Gemfile.'
|
|
174
106
|
rdoc_options: []
|
|
175
107
|
require_paths:
|
|
176
108
|
- lib
|
|
@@ -178,15 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
178
110
|
requirements:
|
|
179
111
|
- - ">="
|
|
180
112
|
- !ruby/object:Gem::Version
|
|
181
|
-
version: 2.
|
|
113
|
+
version: 2.3.0
|
|
182
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
115
|
requirements:
|
|
184
116
|
- - ">="
|
|
185
117
|
- !ruby/object:Gem::Version
|
|
186
118
|
version: '0'
|
|
187
119
|
requirements: []
|
|
188
|
-
|
|
189
|
-
rubygems_version: 2.7.6
|
|
120
|
+
rubygems_version: 3.1.2
|
|
190
121
|
signing_key:
|
|
191
122
|
specification_version: 4
|
|
192
123
|
summary: Interactive RSpec Fixtures
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
module RSpecFixtures
|
|
2
|
-
# Capture stdout and stderr
|
|
3
|
-
#
|
|
4
|
-
# These methods are borrowed from rspec's built in matchers
|
|
5
|
-
# https://github.com/rspec/rspec-expectations/blob/add9b271ecb1d65f7da5bc8a9dd8c64d81d92303/lib/rspec/matchers/built_in/output.rb
|
|
6
|
-
module CaptureStdout
|
|
7
|
-
def self.capture(block)
|
|
8
|
-
captured_stream = StringIO.new
|
|
9
|
-
|
|
10
|
-
original_stream = $stdout
|
|
11
|
-
$stdout = captured_stream
|
|
12
|
-
|
|
13
|
-
block.call
|
|
14
|
-
|
|
15
|
-
captured_stream.string
|
|
16
|
-
ensure
|
|
17
|
-
$stdout = original_stream
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
module CaptureStderr
|
|
22
|
-
def self.capture(block)
|
|
23
|
-
captured_stream = StringIO.new
|
|
24
|
-
|
|
25
|
-
original_stream = $stderr
|
|
26
|
-
$stderr = captured_stream
|
|
27
|
-
|
|
28
|
-
block.call
|
|
29
|
-
|
|
30
|
-
captured_stream.string
|
|
31
|
-
ensure
|
|
32
|
-
$stderr = original_stream
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|