flakey_spec_catcher 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 +214 -23
- data/lib/flakey_spec_catcher/user_config.rb +4 -1
- data/lib/flakey_spec_catcher/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765b9037e2fff584368572be0d907ce9d3dba0ce04b283615526947cd3fe2ab2
|
4
|
+
data.tar.gz: 18a09d27cf2e5850d0ddd65e8fe6006ffdd365f2fb164f624187aeea17baf841
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ec0601d6583dd288459019b2c686ed83323290d10053be001683e40bcd478850aa3f50b27f88b6c3df5f88cad3cf55ebaf37b7d070833236cb4edb01716af4a
|
7
|
+
data.tar.gz: a97d0fbe2bb48992a938105556cba87fa25ed48e8dff0404b7c0ad4d9fc59c4242bf74c26550418d1e1385dc5ec144de9dca3d1b0bce03af13e6091b247d5bc5
|
data/README.md
CHANGED
@@ -1,12 +1,27 @@
|
|
1
|
-
# Flakey Spec Catcher
|
1
|
+
# Flakey Spec Catcher
|
2
2
|
|
3
3
|
### About:
|
4
4
|
|
5
|
-
This gem is intended to catch and prevent the merging of flakey
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
This gem is intended to catch and prevent the merging of flakey RSpec tests.
|
6
|
+
|
7
|
+
There are two primary usecases for flakey_spec_catcher (FSC):
|
8
|
+
|
9
|
+
1. Git Detection - Make changes to specs, add them to a git commit and then
|
10
|
+
allow FSC to detect changes and re-run only the new/edited tests in your
|
11
|
+
commit many times.
|
12
|
+
|
13
|
+
2. Manual Re-runs - Specify a test to re-run many times regardless of whether it has
|
14
|
+
corresponding changes in yuor commit.
|
15
|
+
|
16
|
+
FSC detects changes by running the equivalent of a git diff
|
17
|
+
between the current branch's commit and the HEAD of Source Control Management (SCM)
|
18
|
+
to detect any changes to files that contain `_spec.rb`. For these files, it will
|
19
|
+
re-run either the changed tests or the whole spec file's test suite a specified
|
20
|
+
number of times based on user configurations.
|
21
|
+
|
22
|
+
If all re-runs that FSC triggers pass, the result of running it
|
23
|
+
will be a status code of 0. If a single re-run fails, a non-zero exit status
|
24
|
+
will result.
|
10
25
|
|
11
26
|
Note that `flakey_spec_catcher` will only detect committed changes, so make sure
|
12
27
|
to add any changed spec files to the commit and amend it if you're testing
|
@@ -15,27 +30,70 @@ locally.
|
|
15
30
|
All that's required is to install the gem and then call its executable,
|
16
31
|
`flakey_spec_catcher`.
|
17
32
|
|
33
|
+
### Why use FSC?
|
34
|
+
|
35
|
+
FSC allows you to specify a usage with which to re-run
|
36
|
+
tests. The default usage is inserting all test cases manually into
|
37
|
+
RSpec::Core::Runner API and then clearing all example and test data between
|
38
|
+
each re-run. So long as RSpec is configured to not reset browser+server
|
39
|
+
configurations between test runs or test suites, re-running tests this way
|
40
|
+
will be the fastest way to ensure that tests are not flakey.
|
41
|
+
If providing a custom usage, FSC will run each re-run
|
42
|
+
as a separate process and will likely incur more significant overhead, however,
|
43
|
+
it may require less tweaking of your existing RSpec configuration.
|
44
|
+
|
45
|
+
If you have setup your environment to use the default usage
|
46
|
+
(RSpec::Core::Runner), FSC will use an RSpec listener to
|
47
|
+
combine your test results and give you a consolidated summary of how many re-runs
|
48
|
+
of each test case failed with a specific assertion.
|
49
|
+
|
50
|
+
FSC is ideal for testing in continuous integration since it will
|
51
|
+
run only created/edited tests and can run them many times in an efficient manner.
|
52
|
+
So long as silent mode is not enabled, FSC will return an exit
|
53
|
+
status that can be used to fail a build if flakey specs are detected.
|
54
|
+
|
55
|
+
### What do I need to run FSC?
|
56
|
+
|
57
|
+
You'll need to be running in a git repository for FSC to detect
|
58
|
+
changes. You'll also need to have at least one commit merged in SCM so that
|
59
|
+
FSC has a baseline for comparison.
|
60
|
+
|
61
|
+
Ensure that your gem dependencies meet the base requirements specified by
|
62
|
+
flakey_spec_catcher.gemspec
|
63
|
+
|
64
|
+
### Tips for running FSC efficiently
|
65
|
+
|
66
|
+
In order to run FSC in the most efficient way via RSpec::Core::Runner,
|
67
|
+
you'll need to ensure that your browser+server connections do not reset before/after
|
68
|
+
each example or example group if using Selenium. If RSpec has additional dependencies,
|
69
|
+
you'll also need to ensure that FSC has access to any needed gems.
|
70
|
+
It's best to do this by adding flakey_speec_catcher to your Gemfile via bundler
|
71
|
+
and then running it with `bundle exec flakey_spec_catcher`
|
72
|
+
|
73
|
+
### In what cases if FSC not suitable?
|
74
|
+
|
75
|
+
Since FSC by default re-runs tests at the smallest possible level of
|
76
|
+
change (a single test case or example), it is not suitable to allow it to run
|
77
|
+
on non-idempotent tests, or any kind of test that cannot be re-run on its own repeatedly.
|
78
|
+
For any such tests, applicable test files may be excluded or specific examples may
|
79
|
+
be tagged and those tags can then be excluded in runtime.
|
80
|
+
|
18
81
|
### Install:
|
19
82
|
|
20
83
|
```sh
|
21
84
|
gem install flakey_spec_catcher
|
22
85
|
```
|
23
86
|
|
24
|
-
Or add it
|
25
|
-
|
26
|
-
```ruby
|
27
|
-
# Gemfile
|
28
|
-
gem 'flakey_spec_catcher'
|
29
|
-
```
|
30
|
-
|
31
|
-
and install with Bundler:
|
87
|
+
Or add it using bundler
|
32
88
|
|
33
89
|
```sh
|
90
|
+
bundle add flakey_spec_catcher
|
34
91
|
bundle install
|
35
92
|
```
|
36
93
|
|
37
94
|
### Configuration:
|
38
95
|
|
96
|
+
#### Environment Variables
|
39
97
|
In some cases, certain environment variables can be configured:
|
40
98
|
|
41
99
|
- `FSC_REPEAT_FACTOR`: Number of times the examples in each file will be run.
|
@@ -44,8 +102,8 @@ In some cases, certain environment variables can be configured:
|
|
44
102
|
- `FSC_IGNORE_FILES`: Specify changed files that will be exempt from FSC
|
45
103
|
re-runs. Regex matching is allowed.
|
46
104
|
|
47
|
-
- `FSC_IGNORE_BRANCHES`:
|
48
|
-
branch
|
105
|
+
- `FSC_IGNORE_BRANCHES`: Disable running flakey_spec_catcher in git detection
|
106
|
+
mode on any commits occurring on a specified branch.
|
49
107
|
|
50
108
|
- `FSC_SILENT_MODE`: If 'true', FSC will return back with a exit status 0
|
51
109
|
regardless of the result. If 'false', FSC will return a non-zero exit status
|
@@ -60,6 +118,20 @@ In some cases, certain environment variables can be configured:
|
|
60
118
|
'spec/ui' with `bundle exec rspec` and want your 'spec/api' changes to be
|
61
119
|
re-run with `parallel_rspec`, you could specify the following value:
|
62
120
|
`FSC_USAGE_PATTERNS='{ spec/ui/** => bundle exec rspec }, { spec/api => parallel_rspec }'`
|
121
|
+
Note that by specifying a usage pattern, you will be running a separate process
|
122
|
+
for each re-run and runtimes will suffer. This should only be used when re-running
|
123
|
+
via RSpec::Core::Runner (default usage) is not suitable
|
124
|
+
|
125
|
+
- `FSC_EXCLUDED_TAGS`: Specify tags to exclude from re-runs. If a given example/testcase
|
126
|
+
matches any of the specified tags, then that testcase will be excluded from the
|
127
|
+
re-run queue. Tags may contain a corresponding value that is either a symbol or string and
|
128
|
+
multiple tag name value pairs may be specified in a comma separated list.
|
129
|
+
For example, if a testcase contains a description such as
|
130
|
+
`it 'tests controller functionality', :tag1 => 'enabled' do`
|
131
|
+
then this test could be excluded using
|
132
|
+
`FSC_EXCLUDED_TAGS=':tag1 => enabled'.
|
133
|
+
Note: examples do not inherit the tags from their parent example groups or parent contexts.
|
134
|
+
|
63
135
|
|
64
136
|
Any of these environment variables can be overriden in the commit message by adding the environment variable key and
|
65
137
|
usage/value according to the accepted values specified above.
|
@@ -75,20 +147,127 @@ FSC_USAGE_PATTERNS = '{ spec/ui => bundle exec rspec }, { spec/api => parallel_r
|
|
75
147
|
|
76
148
|
```
|
77
149
|
|
150
|
+
#### Command Line Arguments
|
151
|
+
```
|
152
|
+
-t, --test=TEST_NAME Specify one or more specs in comma separated list
|
153
|
+
-u, --usage=USAGE Specify a re-run usage for the manual re-run
|
154
|
+
-r, --repeat=REPEAT_FACTOR Specify a repeat factor for the manual re-run(s)
|
155
|
+
-e --excluded-tags=EXCLUDED Specify tags to exclude in a comma separated list
|
156
|
+
-v, --version Prints current flakey_spec_catcher_version
|
157
|
+
-h, --help Displays available flakey_spec_catcher cli overrides
|
158
|
+
```
|
159
|
+
|
160
|
+
Examples:
|
161
|
+
|
162
|
+
```
|
163
|
+
# Re-run spec/test_spec.rb:4 50 times using RSpec::Core::Runner
|
164
|
+
flakey_spec_catcher --test='spec/test_spec.rb:4' --repeat='50'
|
165
|
+
|
166
|
+
# Re-run all tests in spec/test_spec.rb 50 times each using 'bundle exec rspc' for
|
167
|
+
# each re-run (at a file level since no line number is specified)
|
168
|
+
flakey_spec_catcher --test='spec/test_spec.rb' --repeat='50' --usage='bundle exec rspec'
|
169
|
+
|
170
|
+
# Re-run all tests found by git detection and exclude tests that
|
171
|
+
# have the tags :flakey or :unsuccessful => true
|
172
|
+
flakey_spec_catcher --excluded-tags=':flakey, :unsuccessful => true'
|
173
|
+
|
174
|
+
```
|
175
|
+
|
78
176
|
### Manually re-running a test:
|
79
177
|
|
80
178
|
Once the gem has been installed, you may manually specify a test to run along with a custom usage
|
81
179
|
(if none is provided, the specified test will run with RSpec::Core::Runner) and a repeat_factor.
|
82
180
|
If no repeat_factor is provided, FSC will check ENV['FSC_REPEAT_FACTOR'] to see if a value
|
83
|
-
has been configured. If none was provided, it will fall back on the default of
|
181
|
+
has been configured. If none was provided, it will fall back on the default of 20 re-runs
|
84
182
|
|
85
183
|
Usage Examples:
|
86
184
|
```
|
185
|
+
# Re-run api/spec/user_spec.rb:3 using RSpec::Core::Runner (default usage) 15 times
|
87
186
|
flakey_spec_catcher --test='api/spec/user_spec.rb:3' --repeat='15'
|
187
|
+
|
188
|
+
# Re-run all files matching the glob api/spec/*_spec.rb in a separate process using
|
189
|
+
# 'bundle exec parallel_rspec' FSC_REPEAT_FACTOR times each
|
88
190
|
flakey_spec_catcher --test='api/spec/*_spec.rb' --usage='bundle exec parallel_rspec'
|
191
|
+
|
192
|
+
# Re-run api/spec/admin_spec.rb in a separate process using rspec, 10 times each
|
89
193
|
flakey_spec_catcher --test='api/spec/admin_spec.rb' --repeat='10' --usage='rspec'
|
90
194
|
```
|
91
195
|
|
196
|
+
### Additional Git Detection Examples
|
197
|
+
|
198
|
+
```sh
|
199
|
+
# Run git detection mode and exclude tests that have the tags :flakey or :unsuccessful => true
|
200
|
+
# run each test 20 times (default) each
|
201
|
+
bundle exec flakey_spec_catcher --excluded-tags=':flakey, :unsuccessful => true'
|
202
|
+
```
|
203
|
+
|
204
|
+
```sh
|
205
|
+
export FSC_REPEAT_FACTOR='10'
|
206
|
+
export FSC_RERUN_FILE_ONLY='true'
|
207
|
+
export FSC_IGNORE_FILES='test_spec.rb'
|
208
|
+
|
209
|
+
# Run git detection mode, exclude any tests that match /test_spec.rb/ 10 times each
|
210
|
+
# if a change is found in any other *_spec.rb file, all tests in that file will be re-run
|
211
|
+
bundle exec flakey_spec_catcher
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
### Full example
|
216
|
+
1. In a repo, changes are made to spec files that are then added to a git commit.
|
217
|
+
2. Run flakey_spec_catcher with any desired user configurations
|
218
|
+
|
219
|
+
Example Output:
|
220
|
+
```Flakey Spec Catcher Settings:
|
221
|
+
Current Branch: master
|
222
|
+
Remote: origin
|
223
|
+
Current Sha: 12341234123412341234123412341234
|
224
|
+
Base Sha: 56785678567856785678567856785678
|
225
|
+
Repeat factor: 20
|
226
|
+
Changed Specs Detected: ["api/spec/changed_spec1.rb:2", "api/spec/changed_spec.rb:3",
|
227
|
+
"ui/spec/new_spec.rb:3", "ui/spec/new_spec.rb: 5",
|
228
|
+
]
|
229
|
+
|
230
|
+
********************************************
|
231
|
+
Re-run Preview
|
232
|
+
Running api/spec/changed_spec1.rb:2 20 times
|
233
|
+
Running api/spec/changed_spec1.rb:3 20 times
|
234
|
+
Running ui/spec/new_spec.rb:3 20 times
|
235
|
+
Running ui/spec/new_spec.rb:5 20 times
|
236
|
+
********************************************
|
237
|
+
|
238
|
+
********** SUMMARY **********
|
239
|
+
2 example(s) ran 20 times without any failures
|
240
|
+
|
241
|
+
*************************************************
|
242
|
+
No Flakiness Detected!
|
243
|
+
*************************************************
|
244
|
+
```
|
245
|
+
|
246
|
+
If any of the tests were flakey, output would resemble something like
|
247
|
+
|
248
|
+
```********** SUMMARY **********
|
249
|
+
1 example(s) ran 20 times without any failures
|
250
|
+
|
251
|
+
Test Description (./api/spec/test_spec.rb:2)
|
252
|
+
|
253
|
+
FAILED 15 / 20 times
|
254
|
+
5 times with exception message:
|
255
|
+
expected: 1
|
256
|
+
got: 0
|
257
|
+
|
258
|
+
(compared using ==)
|
259
|
+
5 times with exception message:
|
260
|
+
expected: 1
|
261
|
+
got: 2
|
262
|
+
|
263
|
+
(compared using ==)
|
264
|
+
5 times with exception message:
|
265
|
+
expected: 1
|
266
|
+
got: 3
|
267
|
+
|
268
|
+
(compared using ==)
|
269
|
+
```
|
270
|
+
|
92
271
|
### How FSC works:
|
93
272
|
|
94
273
|
1. GitController runs a git diff and creates a ChangeSummary object to
|
@@ -98,15 +277,18 @@ flakey_spec_catcher --test='api/spec/admin_spec.rb' --repeat='10' --usage='rspec
|
|
98
277
|
3. After representing all changed code blocks as ChangeContext objects within
|
99
278
|
a ChangeCapsule (one per file), ChangeCapsules are stored in the
|
100
279
|
CapsuleManager.
|
101
|
-
4.
|
102
|
-
|
103
|
-
5.
|
280
|
+
4. Command line interface overrides are retrieved using the CLIOverride class
|
281
|
+
and a referece to a CLIOverride instance is set in the UserConfig instance.
|
282
|
+
5. User Configurations are parsed using the UserConfig class for environment variables
|
283
|
+
and are set for any user configurations that don't have an existing CLIOverride
|
284
|
+
provided value.
|
285
|
+
6. UserConfig and CapsuleManager objects are used to initialize a RerunManager
|
104
286
|
object which creates a RerunCapsule object for each ChangeContext and pairs it
|
105
287
|
with an rspec usage based on user configurations.
|
106
|
-
|
288
|
+
7. RerunManager determines thee re-runs based on user settings and
|
107
289
|
passes back the identified file/test changes to the Runner along with their
|
108
290
|
specified usages.
|
109
|
-
|
291
|
+
8. Runner will re-run each of the changes at a file level or the specific
|
110
292
|
context-level of each test and will exit with a 0 if all changes passed all of
|
111
293
|
their re-runs or a non-zero exit status (passed from RSpec).
|
112
294
|
|
@@ -155,13 +337,22 @@ code health and code coverage are both assessed in SonarQube.
|
|
155
337
|
See: <https://sonarqube.core.inseng.net/dashboard?id=tab%3Aflakey_spec_catcher>
|
156
338
|
|
157
339
|
To test your FSC changes, we've setup some scripts that will build docker images
|
158
|
-
and run
|
340
|
+
and run the FSC specs in the latest ruby versions.
|
159
341
|
|
160
342
|
```sh
|
161
343
|
bash bin/build
|
162
344
|
bash bin/test
|
163
345
|
```
|
164
346
|
|
347
|
+
To build the gem locally and test out FSC in another repository:
|
348
|
+
|
349
|
+
```sh
|
350
|
+
gem build flakey_spec_catcher.gemspec
|
351
|
+
gem install flakey_spc_catcher-<MAJOR-MINOR-PATCH>.gem
|
352
|
+
<cd to repo for testing>
|
353
|
+
flakey_spec_catcher <ARGS>
|
354
|
+
```
|
355
|
+
|
165
356
|
### License:
|
166
357
|
|
167
358
|
MIT. See LICENSE.txt for details.
|
@@ -14,7 +14,8 @@ module FlakeySpecCatcher
|
|
14
14
|
attr_reader :enable_runs
|
15
15
|
|
16
16
|
USER_CONFIG_ENV_VARS = %w[FSC_REPEAT_FACTOR FSC_IGNORE_FILES FSC_IGNORE_BRANCHES
|
17
|
-
FSC_SILENT_MODE FSC_RERUN_FILE_ONLY FSC_USAGE_PATTERNS
|
17
|
+
FSC_SILENT_MODE FSC_RERUN_FILE_ONLY FSC_USAGE_PATTERNS
|
18
|
+
FSC_EXCLUDED_TAGS].freeze
|
18
19
|
|
19
20
|
def initialize(cli_override: CliOverride.new)
|
20
21
|
apply_env_var_settings
|
@@ -150,6 +151,8 @@ module FlakeySpecCatcher
|
|
150
151
|
@rerun_file_only = env_var_string_to_bool(env_value)
|
151
152
|
when 'FSC_USAGE_PATTERNS'
|
152
153
|
@rspec_usage_patterns = env_var_string_to_pairs(env_value)
|
154
|
+
when 'FSC_EXCLUDED_TAGS'
|
155
|
+
@excluded_tags = env_var_string_to_tags(env_value)
|
153
156
|
end
|
154
157
|
end
|
155
158
|
# rubocop:enable Metrics/CyclomaticComplexity
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flakey_spec_catcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Watson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-01-
|
13
|
+
date: 2020-01-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|