rspec-tracer 0.7.0 → 0.9.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 +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +331 -260
- data/lib/rspec_tracer/cache.rb +8 -3
- data/lib/rspec_tracer/configuration.rb +12 -23
- data/lib/rspec_tracer/html_reporter/reporter.rb +15 -3
- data/lib/rspec_tracer/remote_cache/aws.rb +178 -0
- data/lib/rspec_tracer/remote_cache/cache.rb +36 -144
- data/lib/rspec_tracer/remote_cache/repo.rb +175 -0
- data/lib/rspec_tracer/remote_cache/validator.rb +52 -0
- data/lib/rspec_tracer/reporter.rb +79 -4
- data/lib/rspec_tracer/rspec_runner.rb +14 -4
- data/lib/rspec_tracer/runner.rb +29 -0
- data/lib/rspec_tracer/version.rb +1 -1
- data/lib/rspec_tracer.rb +17 -13
- metadata +13 -8
- data/lib/rspec_tracer/remote_cache/git.rb +0 -113
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
[](https://codeclimate.com/github/avmnu-sng/rspec-tracer/maintainability)
|
4
|
+
[](https://codeclimate.com/github/avmnu-sng/rspec-tracer/test_coverage)
|
5
|
+
[](https://badge.fury.io/rb/rspec-tracer)
|
6
|
+
|
7
|
+
RSpec Tracer is a **specs dependency analyzer**, **flaky tests detector**, **tests accelerator**,
|
8
|
+
and **coverage reporter** tool. It maintains a list of files for each test, enabling
|
9
|
+
itself to skip tests in the subsequent runs if none of the dependent files are changed.
|
6
10
|
|
7
11
|
It uses [Ruby's built-in coverage library](https://ruby-doc.org/stdlib/libdoc/coverage/rdoc/Coverage.html)
|
8
12
|
to keep track of the coverage for each test. For each test executed, the coverage
|
@@ -18,45 +22,23 @@ Knowing the examples and files dependency gives us a better insight into the cod
|
|
18
22
|
and we have **a clear idea of what to test for when making any changes**. With this data,
|
19
23
|
we can also analyze the coupling between different components and much more.
|
20
24
|
|
21
|
-
|
25
|
+
RSpec Tracer requires **Ruby 2.5+** and **rspec-core >= 3.6.0**. To use with **Rails 5+**,
|
26
|
+
make sure to use **rspec-rails >= 4.0.0**. If you are using SimpleCov, it is
|
27
|
+
recommended to use **simplecov >= 0.12.0**. To use RSpec Tracer **cache on CI**, you
|
28
|
+
need to have an **S3 bucket** and **[AWS CLI](https://aws.amazon.com/cli/)**
|
29
|
+
installed.
|
22
30
|
|
23
|
-
You should take some time and go through the **[document](./RSPEC_TRACER.md)** describing
|
24
|
-
the **intention** and implementation details of **managing dependency**, **managing flaky tests**,
|
25
|
-
**skipping tests**, and **caching on CI**. You must go through the README file before
|
26
|
-
integrating the gem into your project to better understand what is happening.
|
31
|
+
### You should take some time and go through the **[document](./RSPEC_TRACER.md)** describing the **intention** and implementation details of **managing dependency**, **managing flaky tests**, **skipping tests**, and **caching on CI**.
|
27
32
|
|
28
33
|
## Table of Contents
|
29
34
|
|
30
35
|
* [Demo](#demo)
|
31
|
-
* [Installation](#installation)
|
32
|
-
* [Compatibility](#compatibility)
|
33
|
-
* [Additional Tools](#additional-tools)
|
34
36
|
* [Getting Started](#getting-started)
|
35
|
-
* [
|
36
|
-
|
37
|
-
* [CI](#ci)
|
38
|
-
* [LOCAL_AWS](#local_aws)
|
39
|
-
* [RSPEC_TRACER_NO_SKIP](#rspec_tracer_no_skip)
|
40
|
-
* [RSPEC_TRACER_S3_URI](#rspec_tracer_s3_uri)
|
41
|
-
* [RSPEC_TRACER_UPLOAD_LOCAL_CACHE](#rspec_tracer_upload_local_cache)
|
42
|
-
* [RSPEC_TRACER_VERBOSE](#rspec_tracer_verbose)
|
43
|
-
* [TEST_SUITES](#test_suites)
|
44
|
-
* [TEST_SUITE_ID](#test_suite_id)
|
45
|
-
* [Sample Reports](#sample-reports)
|
46
|
-
* [Examples](#examples)
|
47
|
-
* [Flaky Examples](#flaky-examples)
|
48
|
-
* [Examples Dependency](#examples-dependency)
|
49
|
-
* [Files Dependency](#files-dependency)
|
50
|
-
* [Configuring RSpec Tracer](#configuring-rspec-tracer)
|
37
|
+
* [Configuring CI Caching](#configuring-ci-caching)
|
38
|
+
* [Advanced Configuration](#advanced-configuration)
|
51
39
|
* [Filters](#filters)
|
52
|
-
|
53
|
-
|
54
|
-
* [Regex Filter](#regex-filter)
|
55
|
-
* [Block Filter](#block-filter)
|
56
|
-
* [Array Filter](#array-filter)
|
57
|
-
* [Contributing](#contributing)
|
58
|
-
* [License](#license)
|
59
|
-
* [Code of Conduct](#code-of-conduct)
|
40
|
+
* [Environment Variables](#environment-variables)
|
41
|
+
* [When Should You Not Use RSpec Tracer](#when-should-you-not-use-rspec-tracer)
|
60
42
|
|
61
43
|
## Demo
|
62
44
|
|
@@ -66,317 +48,406 @@ integrating the gem into your project to better understand what is happening.
|
|
66
48
|
**Next Run**
|
67
49
|

|
68
50
|
|
51
|
+
You get the following three reports:
|
69
52
|
|
70
|
-
|
53
|
+
### All Examples Report
|
71
54
|
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
gem 'rspec-tracer', '~> 0.6', group: :test, require: false
|
75
|
-
```
|
55
|
+
These reports provide basic test information:
|
76
56
|
|
77
|
-
|
78
|
-
```
|
79
|
-
/rspec_tracer_cache/
|
80
|
-
/rspec_tracer_coverage/
|
81
|
-
/rspec_tracer_report/
|
82
|
-
```
|
57
|
+
**First Run**
|
83
58
|
|
84
|
-
|
59
|
+

|
85
60
|
|
86
|
-
|
87
|
-
make sure to use **rspec-rails >= 4.0.0**. If you are using SimpleCov, it is
|
88
|
-
recommended to use **simplecov >= 0.12.0**.
|
61
|
+
**Next Run**
|
89
62
|
|
90
|
-
|
63
|
+

|
91
64
|
|
92
|
-
|
93
|
-
**[AWS CLI](https://aws.amazon.com/cli/)** installed.
|
65
|
+
### Flaky Examples Report
|
94
66
|
|
95
|
-
|
67
|
+
These reports provide flaky tests information. Assuming **the following two tests
|
68
|
+
failed in the first run.**
|
96
69
|
|
97
|
-
|
70
|
+
**Next Run**
|
98
71
|
|
99
|
-
|
72
|
+

|
100
73
|
|
101
|
-
|
102
|
-
and launch:
|
74
|
+
**Another Run**
|
103
75
|
|
104
|
-
|
105
|
-
require 'simplecov'
|
106
|
-
SimpleCov.start
|
76
|
+

|
107
77
|
|
108
|
-
|
109
|
-
require 'rspec_tracer'
|
110
|
-
RSpecTracer.start
|
111
|
-
```
|
78
|
+
### Examples Dependency Report
|
112
79
|
|
113
|
-
|
114
|
-
- SimpleCov **won't be able to provide branch coverage report** even when enabled.
|
115
|
-
- RSpec Tracer **nullifies the `SimpleCov.at_exit`** callback.
|
80
|
+
These reports show a list of dependent files for each test.
|
116
81
|
|
117
|
-
|
82
|
+

|
118
83
|
|
119
|
-
|
120
|
-
`test/test_helper.rb`). Note that `RSpecTracer.start` must be issued **before loading
|
121
|
-
any of the application code.**
|
84
|
+
### Files Dependency Report
|
122
85
|
|
123
|
-
|
124
|
-
# Load RSpec Tracer
|
125
|
-
require 'rspec_tracer'
|
126
|
-
RSpecTracer.start
|
127
|
-
```
|
86
|
+
These reports provide information on the total number of tests that will run after changing this particular file.
|
128
87
|
|
129
|
-
|
130
|
-
Rakefile in your project to have the following:
|
88
|
+

|
131
89
|
|
132
|
-
```ruby
|
133
|
-
spec = Gem::Specification.find_by_name('rspec-tracer')
|
134
90
|
|
135
|
-
|
136
|
-
```
|
137
|
-
3. Before running tests, download the remote cache using the following rake task:
|
91
|
+
## Getting Started
|
138
92
|
|
139
|
-
|
140
|
-
|
93
|
+
1. Add this line to your `Gemfile` and `bundle install`:
|
94
|
+
```ruby
|
95
|
+
gem 'rspec-tracer', '~> 0.9', group: :test, require: false
|
141
96
|
```
|
142
|
-
4. Run the tests with RSpec using `bundle exec rspec`.
|
143
|
-
5. After running tests, upload the local cache using the following rake task:
|
144
97
|
|
145
|
-
|
146
|
-
bundle exec rake rspec_tracer:remote_cache:upload
|
98
|
+
And, add the followings to your `.gitignore`:
|
147
99
|
```
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
### BUNDLE_PATH
|
157
|
-
|
158
|
-
Since the bundler uses a vendor directory inside the project, it might cause slowness
|
159
|
-
depending on the vendor size. You can configure the bundle path outside of the project
|
160
|
-
using `BUNDLE_PATH` environment variable, for example, `BUNDLE_PATH=$HOME/vendor/bundle`.
|
161
|
-
Make sure to cache this directory in the CI configuration.
|
162
|
-
|
163
|
-
### CI
|
164
|
-
|
165
|
-
Mostly all the CI have `CI=true`. If not, you should explicitly set it to `true`.
|
166
|
-
|
167
|
-
### LOCAL_AWS
|
168
|
-
|
169
|
-
In case you want to test out the caching feature in the local development environment.
|
170
|
-
You can install [localstack](https://github.com/localstack/localstack) and
|
171
|
-
[awscli-local](https://github.com/localstack/awscli-local) and then invoke the
|
172
|
-
rake tasks with `LOCAL_AWS=true`.
|
173
|
-
|
174
|
-
### RSPEC_TRACER_NO_SKIP
|
175
|
-
|
176
|
-
The default value is `false.` If set to `true`, the RSpec Tracer will not skip
|
177
|
-
any tests. Note that it will continue to maintain cache files and generate reports.
|
178
|
-
|
179
|
-
```ruby
|
180
|
-
RSPEC_TRACER_NO_SKIP=true bundle exec rspec
|
181
|
-
```
|
182
|
-
|
183
|
-
### RSPEC_TRACER_S3_URI
|
184
|
-
|
185
|
-
You should provide the S3 bucket path to store the cache files.
|
186
|
-
|
187
|
-
```ruby
|
188
|
-
export RSPEC_TRACER_S3_URI=s3://ci-artifacts-bucket/rspec-tracer-cache
|
189
|
-
```
|
100
|
+
/rspec_tracer_cache/
|
101
|
+
/rspec_tracer_coverage/
|
102
|
+
/rspec_tracer_report/
|
103
|
+
```
|
104
|
+
2. Load and launch RSpec Tracer at the very top of `spec_helper.rb` (or `rails_helper.rb`,
|
105
|
+
`test/test_helper.rb`). Note that `RSpecTracer.start` must be issued **before loading
|
106
|
+
any of the application code.**
|
190
107
|
|
191
|
-
|
108
|
+
```ruby
|
109
|
+
# Load RSpec Tracer
|
110
|
+
require 'rspec_tracer'
|
111
|
+
RSpecTracer.start
|
112
|
+
```
|
192
113
|
|
193
|
-
|
194
|
-
|
114
|
+
**If you are using SimpleCov**, load RSpec Tracer right after the SimpleCov load
|
115
|
+
and launch:
|
195
116
|
|
196
|
-
|
117
|
+
```ruby
|
118
|
+
require 'simplecov'
|
119
|
+
SimpleCov.start
|
197
120
|
|
198
|
-
|
121
|
+
# Load RSpec Tracer
|
122
|
+
require 'rspec_tracer'
|
123
|
+
RSpecTracer.start
|
124
|
+
```
|
199
125
|
|
200
|
-
|
201
|
-
|
202
|
-
```
|
126
|
+
If you use RSpec Tracer with SimpleCov, then **SimpleCov would not report branch
|
127
|
+
coverage results even when enabled**.
|
203
128
|
|
204
|
-
|
129
|
+
3. After running your tests, open `rspec_tracer_report/index.html` in the browser
|
130
|
+
of your choice.
|
205
131
|
|
206
|
-
|
207
|
-
number of different test suites you are running.
|
132
|
+
## Configuring CI Caching
|
208
133
|
|
134
|
+
To enable RSpec Tracer to share cache between different builds on CI, update the
|
135
|
+
Rakefile in your project to have the following:
|
209
136
|
```ruby
|
210
|
-
|
211
|
-
```
|
212
|
-
|
213
|
-
### TEST_SUITE_ID
|
137
|
+
spec = Gem::Specification.find_by_name('rspec-tracer')
|
214
138
|
|
215
|
-
|
216
|
-
separate groups. This way, RSpec Tracer is not overwhelmed with loading massive
|
217
|
-
cached data in the memory. Also, it generates and uses cache for specific test suites
|
218
|
-
and not merge them.
|
219
|
-
|
220
|
-
```ruby
|
221
|
-
TEST_SUITE_ID=1 bundle exec rspec spec/models
|
222
|
-
TEST_SUITE_ID=2 bundle exec rspec spec/helpers
|
139
|
+
load "#{spec.gem_dir}/lib/rspec_tracer/remote_cache/Rakefile"
|
223
140
|
```
|
224
141
|
|
225
|
-
|
226
|
-
the total number of test suites when downloading the cache files.
|
227
|
-
|
142
|
+
Before running tests, download the remote cache using the following rake task:
|
228
143
|
```sh
|
229
|
-
|
144
|
+
bundle exec rake rspec_tracer:remote_cache:download
|
230
145
|
```
|
231
146
|
|
232
|
-
|
233
|
-
the S3 for each test suite, not just for the current one. Also, while uploading,
|
234
|
-
make sure to provide the test suite id.
|
235
|
-
|
147
|
+
After running tests, upload the local cache using the following rake task:
|
236
148
|
```sh
|
237
|
-
|
149
|
+
bundle exec rake rspec_tracer:remote_cache:upload
|
238
150
|
```
|
239
151
|
|
240
|
-
|
241
|
-
|
242
|
-
You get the following three reports:
|
243
|
-
|
244
|
-
### Examples
|
245
|
-
|
246
|
-
These reports provide basic test information:
|
247
|
-
|
248
|
-
**First Run**
|
249
|
-
|
250
|
-

|
251
|
-
|
252
|
-
**Next Run**
|
253
|
-
|
254
|
-

|
152
|
+
You must set the following two environment variables:
|
255
153
|
|
256
|
-
|
154
|
+
- **`GIT_BRANCH`** is the git branch name you are running the CI build on.
|
155
|
+
- **`RSPEC_TRACER_S3_URI`** is the S3 bucket path to store the cache files.
|
156
|
+
```sh
|
157
|
+
export RSPEC_TRACER_S3_URI=s3://ci-artifacts-bucket/rspec-tracer-cache
|
158
|
+
```
|
257
159
|
|
258
|
-
|
259
|
-
failed in the first run.**
|
160
|
+
## Advanced Configuration
|
260
161
|
|
261
|
-
|
162
|
+
Configuration settings can be applied in three formats, which are completely equivalent:
|
262
163
|
|
263
|
-
|
164
|
+
- The most common way is to configure it directly in your start block:
|
165
|
+
```ruby
|
166
|
+
RSpecTracer.start do
|
167
|
+
config_option 'foo'
|
168
|
+
end
|
169
|
+
```
|
170
|
+
- You can also set all configuration options directly:
|
171
|
+
```ruby
|
172
|
+
RSpecTracer.config_option 'foo'
|
173
|
+
```
|
264
174
|
|
265
|
-
|
175
|
+
- If you do not want to start tracer immediately after launch or want to add
|
176
|
+
additional configuration later on in a concise way, use:
|
177
|
+
```ruby
|
178
|
+
RSpecTracer.configure do
|
179
|
+
config_option 'foo'
|
180
|
+
end
|
181
|
+
```
|
266
182
|
|
267
|
-
|
183
|
+
The available configuration options are:
|
268
184
|
|
269
|
-
|
185
|
+
- **`root dir`** to set the project root. The default value is the current working
|
186
|
+
directory.
|
187
|
+
- **`add_filter filter`** to apply [filters](#filters) on the source files to
|
188
|
+
exclude them from the dependent files list.
|
189
|
+
- **`filters.clear`** to remove the default configured dependent files filters.
|
190
|
+
- **`add_coverage_filter filter`** to apply [filters](#filters) on the source files
|
191
|
+
to exclude them from the coverage report.
|
192
|
+
- **`coverage_filters.clear`** to remove the default configured coverage files filters.
|
193
|
+
- **`coverage_track_files glob`** to include files in the given glob pattern in
|
194
|
+
the coverage report if these files are not already present.
|
270
195
|
|
271
|
-
|
196
|
+
```ruby
|
197
|
+
RSpecTracer.start do
|
198
|
+
# Configure project root
|
199
|
+
root '/tmp/my_project'
|
272
200
|
|
273
|
-
|
201
|
+
# Clear existing filters
|
202
|
+
filters.clear
|
203
|
+
# Add dependent files filter
|
204
|
+
add_filter %r{^/tasks/}
|
274
205
|
|
275
|
-
|
206
|
+
# Clear existing coverage filters
|
207
|
+
coverage_filters.clear
|
208
|
+
# Add coverage files filter
|
209
|
+
add_coverage_filter %w[/features/ /spec/ /tests/]
|
276
210
|
|
277
|
-
|
211
|
+
# Define glob to track files in the coverage report
|
212
|
+
coverage_track_files '{app,lib}/**/*.rb'
|
213
|
+
end
|
214
|
+
```
|
278
215
|
|
279
|
-
|
216
|
+
You can configure the RSpec Tracer reports directories using the following environment
|
217
|
+
variables:
|
218
|
+
|
219
|
+
- **`RSPEC_TRACER_CACHE_DIR`** to update the default cache directory (`rspec_tracer_cache`).
|
220
|
+
```sh
|
221
|
+
export RSPEC_TRACER_CACHE_DIR=/tmp/rspec_tracer_cache
|
222
|
+
```
|
223
|
+
- **`RSPEC_TRACER_COVERAGE_DIR`** to update the default coverage directory (`rspec_tracer_coverage`).
|
224
|
+
```sh
|
225
|
+
export RSPEC_TRACER_CACHE_DIR=/tmp/rspec_tracer_coverage
|
226
|
+
```
|
227
|
+
- **`RSPEC_TRACER_REPORT_DIR`** to update the default html reports directory (`rspec_tracer_report`).
|
228
|
+
```sh
|
229
|
+
export RSPEC_TRACER_CACHE_DIR=/tmp/rspec_tracer_report
|
230
|
+
```
|
231
|
+
|
232
|
+
These settings are available through environment variables because the rake tasks
|
233
|
+
to download and upload the cache files need to use the same directories.
|
280
234
|
|
281
|
-
##
|
235
|
+
## Filters
|
282
236
|
|
283
|
-
|
237
|
+
By default, RSpec Tracer ignores all the files outside of the project root directory -
|
238
|
+
otherwise you would end up with the source files in the gems you are using in the
|
239
|
+
project. It also applies the following filters:
|
240
|
+
```ruby
|
241
|
+
RSpecTracer.configure do
|
242
|
+
add_filter '/vendor/bundle/'
|
243
|
+
|
244
|
+
add_coverage_filter %w[
|
245
|
+
/autotest/
|
246
|
+
/features/
|
247
|
+
/spec/
|
248
|
+
/test/
|
249
|
+
/vendor/bundle/
|
250
|
+
].freeze
|
251
|
+
end
|
252
|
+
```
|
284
253
|
|
285
|
-
|
254
|
+
### Defining Custom Filteres
|
286
255
|
|
287
|
-
|
288
|
-
|
289
|
-
|
256
|
+
You can currently define a filter using either a String or Regexp (that will then
|
257
|
+
be Regexp-matched against each source file's name relative to the project root),
|
258
|
+
a block or by passing in your own Filter class.
|
259
|
+
|
260
|
+
- **String Filter**: The string filter matches files that have the given string
|
261
|
+
in their name. For example, the following string filter will remove all files that
|
262
|
+
have `"/helpers/"` in their name.
|
263
|
+
```ruby
|
264
|
+
RSpecTracer.start do
|
265
|
+
add_filter '/helpers/'
|
266
|
+
end
|
267
|
+
```
|
268
|
+
|
269
|
+
- **Regex Filter**: The regex filter removes all files that have a successful name
|
270
|
+
match against the given regex expression. This simple regex filter will remove
|
271
|
+
all files that start with `%r{^/helper/}` in their name:
|
272
|
+
```ruby
|
273
|
+
RSpecTracer.start do
|
274
|
+
add_filter %r{^/helpers/}
|
275
|
+
end
|
276
|
+
```
|
277
|
+
|
278
|
+
- **Block Filter**: Block filters receive a `Hash` object and expect your block
|
279
|
+
to return either **true** (if the file is to be removed from the result) or **false**
|
280
|
+
(if the result should be kept). In the below example, the filter will remove all
|
281
|
+
files that match `"/helpers/"` in their path.
|
282
|
+
```ruby
|
283
|
+
RSpecTracer.start do
|
284
|
+
add_filter do |source_file|
|
285
|
+
source_file[:file_path].include?('/helpers/')
|
290
286
|
end
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
```ruby
|
295
|
-
RSpecTracer.config_option 'foo'
|
296
|
-
```
|
297
|
-
|
298
|
-
- If you do not want to start tracer immediately after launch or want to add
|
299
|
-
additional configuration later on in a concise way, use:
|
287
|
+
end
|
288
|
+
```
|
300
289
|
|
301
|
-
|
302
|
-
|
303
|
-
config_option 'foo'
|
304
|
-
end
|
305
|
-
```
|
290
|
+
You can also use `source_file[:name]` to define the return value of the block
|
291
|
+
filter for the given source file.
|
306
292
|
|
307
|
-
|
293
|
+
- **Array Filter**: You can pass in an array containing any of the other filter types:
|
294
|
+
```ruby
|
295
|
+
RSpecTracer.start do
|
296
|
+
add_filter ['/helpers/', %r{^/utils/}]
|
297
|
+
end
|
298
|
+
```
|
308
299
|
|
309
|
-
|
300
|
+
## Environment Variables
|
310
301
|
|
311
|
-
|
302
|
+
To get better control on execution, you can use the following environment variables
|
303
|
+
whenever required.
|
312
304
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
```
|
318
|
-
- To exclude selected files from the coverage data. You should only use this
|
319
|
-
when not using SimpleCov.
|
305
|
+
- **`LOCAL_AWS (default: false)`:** In case you want to test out the caching feature in the local
|
306
|
+
development environment. You can install [localstack](https://github.com/localstack/localstack)
|
307
|
+
and [awscli-local](https://github.com/localstack/awscli-local) and then invoke the
|
308
|
+
rake tasks with `LOCAL_AWS=true`.
|
320
309
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
end
|
325
|
-
```
|
310
|
+
- **`RSPEC_TRACER_NO_SKIP (default: false)`:** Use this environment variables to
|
311
|
+
not skip any tests. Note that it will continue to maintain cache files and generate
|
312
|
+
reports.
|
326
313
|
|
327
|
-
|
328
|
-
|
329
|
-
|
314
|
+
- **`RSPEC_TRACER_UPLOAD_LOCAL_CACHE (default: false)`:** By default, RSpec Tracer
|
315
|
+
does not upload local cache files. You can set this environment variable to `true`
|
316
|
+
to upload the local cache to S3.
|
330
317
|
|
331
|
-
|
318
|
+
- **`RSPEC_TRACER_VERBOSE (default: false)`:** To print the intermediate steps
|
319
|
+
and time taken, use this environment variable.
|
332
320
|
|
333
|
-
|
334
|
-
|
335
|
-
|
321
|
+
- **`TEST_SUITES`:** Set this environment variable when running parallel builds
|
322
|
+
in the CI. It determines the total number of different test suites you are running.
|
323
|
+
```sh
|
324
|
+
export TEST_SUITES=8
|
325
|
+
```
|
336
326
|
|
337
|
-
|
327
|
+
- **`TEST_SUITE_ID`:** If you have a large set of tests to run, it is recommended
|
328
|
+
to run them in separate groups. This way, RSpec Tracer is not overwhelmed with
|
329
|
+
loading massive cached data in the memory. Also, it generates and uses cache for
|
330
|
+
specific test suites and not merge them.
|
331
|
+
```sh
|
332
|
+
TEST_SUITE_ID=1 bundle exec rspec spec/models
|
333
|
+
TEST_SUITE_ID=2 bundle exec rspec spec/helpers
|
334
|
+
```
|
338
335
|
|
339
|
-
|
340
|
-
RSpecTracer.start do
|
341
|
-
add_filter '/helpers/'
|
342
|
-
end
|
343
|
-
```
|
336
|
+
## When Should You Not Use RSpec Tracer
|
344
337
|
|
345
|
-
|
338
|
+
To uniquely identify the examples is one of the requirements for the correctness
|
339
|
+
of the RSpec Tracer. Sometimes, it would not be possible to do so depending upon
|
340
|
+
how we have written the specs. The following attributes determine the uniqueness:
|
346
341
|
|
347
|
-
|
342
|
+
- The example group
|
343
|
+
- The example full description
|
344
|
+
- The spec file location, i.e., file name and line number
|
345
|
+
- All the shared examples and contexts
|
348
346
|
|
347
|
+
Consider the following `Calculator` module:
|
349
348
|
```ruby
|
350
|
-
|
351
|
-
|
349
|
+
module Calculator
|
350
|
+
module_function
|
351
|
+
|
352
|
+
def add(a, b) a + b; end
|
353
|
+
def sub(a, b) a - b; end
|
354
|
+
def mul(a, b) a * b; end
|
352
355
|
end
|
353
356
|
```
|
354
357
|
|
355
|
-
|
358
|
+
And the corresponding spec file `spec/calculator_spec.rb`:
|
359
|
+
```ruby
|
360
|
+
RSpec.describe Calculator do
|
361
|
+
describe '#add' do
|
362
|
+
[
|
363
|
+
[1, 2, 3],
|
364
|
+
[0, 0, 0],
|
365
|
+
[5, 32, 37],
|
366
|
+
[-1, -8, -9],
|
367
|
+
[10, -10, 0]
|
368
|
+
].each { |a, b, r| it { expect(described_class.add(a, b)).to eq(r) } }
|
369
|
+
end
|
356
370
|
|
357
|
-
|
371
|
+
describe '#sub' do
|
372
|
+
[
|
373
|
+
[1, 2, -1],
|
374
|
+
[10, 0, 10],
|
375
|
+
[37, 5, 32],
|
376
|
+
[-1, -8, 7],
|
377
|
+
[10, 10, 0]
|
378
|
+
].each do |a, b, r|
|
379
|
+
it 'performs subtraction' do
|
380
|
+
expect(described_class.sub(a, b)).to eq(r)
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
358
384
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
385
|
+
describe '#mul' do
|
386
|
+
[
|
387
|
+
[1, 2, -2],
|
388
|
+
[10, 0, 0],
|
389
|
+
[5, 7, 35],
|
390
|
+
[-1, -8, 8],
|
391
|
+
[10, 10, 100]
|
392
|
+
].each do |a, b, r|
|
393
|
+
it "multiplies #{a} and #{b} to #{r}" do
|
394
|
+
expect(described_class.mul(a, b)).to eq(r)
|
395
|
+
end
|
396
|
+
end
|
363
397
|
end
|
364
398
|
end
|
365
399
|
```
|
366
400
|
|
367
|
-
|
368
|
-
|
369
|
-
|
401
|
+
Running the spec with `bundle exec rspec spec/calculator_spec.rb` generates the
|
402
|
+
following output:
|
403
|
+
```
|
404
|
+
Calculator
|
405
|
+
#mul
|
406
|
+
multiplies 5 and 7 to 35
|
407
|
+
multiplies 10 and 10 to 100
|
408
|
+
multiplies 10 and 0 to 0
|
409
|
+
multiplies 1 and 2 to -2 (FAILED - 1)
|
410
|
+
multiplies -1 and -8 to 8
|
411
|
+
#add
|
412
|
+
example at ./spec/calculator_spec.rb:13
|
413
|
+
example at ./spec/calculator_spec.rb:13
|
414
|
+
example at ./spec/calculator_spec.rb:13
|
415
|
+
example at ./spec/calculator_spec.rb:13
|
416
|
+
example at ./spec/calculator_spec.rb:13
|
417
|
+
#sub
|
418
|
+
performs subtraction
|
419
|
+
performs subtraction
|
420
|
+
performs subtraction
|
421
|
+
performs subtraction
|
422
|
+
performs subtraction
|
423
|
+
```
|
370
424
|
|
371
|
-
|
425
|
+
In this scenario, RSpec Tracer cannot determine the `Calculator#add` and
|
426
|
+
`Calculator#sub` group examples. Also, it will ask you not to use the gem unless
|
427
|
+
you have made some changes to your spec files.
|
372
428
|
|
373
|
-
```ruby
|
374
|
-
RSpecTracer.start do
|
375
|
-
add_filter ['/helpers/', %r{^/utils/}]
|
376
|
-
end
|
377
429
|
```
|
378
|
-
|
379
|
-
|
430
|
+
================================================================================
|
431
|
+
IMPORTANT NOTICE -- DO NOT USE RSPEC TRACER
|
432
|
+
================================================================================
|
433
|
+
It would be best to make changes so that the RSpec tracer can uniquely
|
434
|
+
identify all the examples, and then you can enable the RSpec tracer back.
|
435
|
+
================================================================================
|
436
|
+
|
437
|
+
RSpec tracer could not uniquely identify the following 10 examples:
|
438
|
+
- Example ID: eabd51a899db4f64d5839afe96004f03 (5 examples)
|
439
|
+
* Calculator#add (spec/calculator_spec.rb:13)
|
440
|
+
* Calculator#add (spec/calculator_spec.rb:13)
|
441
|
+
* Calculator#add (spec/calculator_spec.rb:13)
|
442
|
+
* Calculator#add (spec/calculator_spec.rb:13)
|
443
|
+
* Calculator#add (spec/calculator_spec.rb:13)
|
444
|
+
- Example ID: 72171b502c5a42b9aa133f165cf09ec2 (5 examples)
|
445
|
+
* Calculator#sub performs subtraction (spec/calculator_spec.rb:24)
|
446
|
+
* Calculator#sub performs subtraction (spec/calculator_spec.rb:24)
|
447
|
+
* Calculator#sub performs subtraction (spec/calculator_spec.rb:24)
|
448
|
+
* Calculator#sub performs subtraction (spec/calculator_spec.rb:24)
|
449
|
+
* Calculator#sub performs subtraction (spec/calculator_spec.rb:24)
|
450
|
+
```
|
380
451
|
|
381
452
|
## Contributing
|
382
453
|
|