rspec-tracer 0.6.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 885e868cf847ca1bab4ba2243cd4cd6a4bc3f936a3c8c10f677146433acc2068
4
- data.tar.gz: d60fcdeef0067a37faec3ea876ffa519bdd7039a1765ad59e551427bcf2c8e29
3
+ metadata.gz: 675be2bd6603501deb282508ea234808f0bbdf60c2b626611919f84c32bb4ba9
4
+ data.tar.gz: 591be21b4e97c50f33385111ac758665a97e83ca82e154cd3b86d32133f7ef52
5
5
  SHA512:
6
- metadata.gz: cffa43507448703f4471ed2a463e7ef486f105b06560663d307b21c3303368b0ae0260bb36bbc392f900bfb0e54482fdc8055d231ab75fb33e5a93360be46ac9
7
- data.tar.gz: d59157d318beda7c81a65cdd1a38ff3d849521a502e31c6c805916ace8f6f3568a5114f201bc03cdb33e63cae3c0a86ae5e81dd148c1c32f735d7d5d3cea5750
6
+ metadata.gz: 1ab8ca453da65dd7185fa4869633d9b9ab85fb5c73cfb45929928a492d58d0e16d24e3bcef2466ceae4408c7e1ad2e5ab3f10137061ab684b1decf885809607d
7
+ data.tar.gz: 8dc1d3078f2c16c8ee5142c03d05222dd0bd458c979bca0a35ee1b1e44fead38ed2c1a6d84795a93f2a4d7a15c58da40562f4dae360f22e65f1518fc0ddecf75
data/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [0.8.0] - 2021-09-13
2
+
3
+ ### Fixed
4
+
5
+ Unable to find cache in case of history rewrites (#33)
6
+
7
+ ## [0.7.0] - 2021-09-10
8
+
9
+ ### Fixed
10
+
11
+ Missing spec files for the gem
12
+
13
+ ## [0.6.2] - 2021-09-07
14
+
15
+ ### Added
16
+
17
+ Improvements towards reducing dependency and coverage processing time (#26)
18
+
19
+ ## [0.6.1] - 2021-09-06
20
+
21
+ ### Fixed
22
+
23
+ Bug in time formatter (#24)
24
+
25
+ ### Added
26
+
27
+ Environment variable to control verbose output (#25)
28
+
1
29
  ## [0.6.0] - 2021-09-05
2
30
 
3
31
  ### Added
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  ![](./readme_files/rspec_tracer.png)
2
2
 
3
- RSpec Tracer is a **specs dependency analysis tool** and a **test skipper for RSpec**.
4
- It maintains a list of files for each test, enabling itself to skip tests in the
5
- subsequent runs if none of the dependent files are changed.
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/eabce2757839c08d8f8d/maintainability)](https://codeclimate.com/github/avmnu-sng/rspec-tracer/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/eabce2757839c08d8f8d/test_coverage)](https://codeclimate.com/github/avmnu-sng/rspec-tracer/test_coverage)
5
+ [![Gem Version](https://badge.fury.io/rb/rspec-tracer.svg)](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,44 +22,24 @@ 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
- ## Note
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)**
32
+ describing the **intention** and implementation details of **managing dependency**,
33
+ **managing flaky tests**, **skipping tests**, and **caching on CI**.
27
34
 
28
35
  ## Table of Contents
29
36
 
30
37
  * [Demo](#demo)
31
- * [Installation](#installation)
32
- * [Compatibility](#compatibility)
33
- * [Additional Tools](#additional-tools)
34
38
  * [Getting Started](#getting-started)
35
- * [Environment Variables](#environment-variables)
36
- * [BUNDLE_PATH](#bundle_path)
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
- * [TEST_SUITES](#test_suites)
43
- * [TEST_SUITE_ID](#test_suite_id)
44
- * [Sample Reports](#sample-reports)
45
- * [Examples](#examples)
46
- * [Flaky Examples](#flaky-examples)
47
- * [Examples Dependency](#examples-dependency)
48
- * [Files Dependency](#files-dependency)
49
- * [Configuring RSpec Tracer](#configuring-rspec-tracer)
39
+ * [Configuring CI Caching](#configuring-ci-caching)
40
+ * [Advanced Configuration](#advanced-configuration)
50
41
  * [Filters](#filters)
51
- * [Defining Custom Filteres](#defining-custom-filteres)
52
- * [String Filter](#string-filter)
53
- * [Regex Filter](#regex-filter)
54
- * [Block Filter](#block-filter)
55
- * [Array Filter](#array-filter)
56
- * [Contributing](#contributing)
57
- * [License](#license)
58
- * [Code of Conduct](#code-of-conduct)
42
+ * [Environment Variables](#environment-variables)
59
43
 
60
44
  ## Demo
61
45
 
@@ -65,259 +49,210 @@ integrating the gem into your project to better understand what is happening.
65
49
  **Next Run**
66
50
  ![](./readme_files/next_run.gif)
67
51
 
52
+ You get the following three reports:
68
53
 
69
- ## Installation
54
+ ### All Examples Report
70
55
 
71
- Add this line to your `Gemfile` and `bundle install`:
72
- ```ruby
73
- gem 'rspec-tracer', group: :test, require: false
74
- ```
56
+ These reports provide basic test information:
75
57
 
76
- And, add the followings to your `.gitignore`:
77
- ```
78
- /rspec_tracer_cache/
79
- /rspec_tracer_coverage/
80
- /rspec_tracer_report/
81
- ```
58
+ **First Run**
82
59
 
83
- ### Compatibility
60
+ ![](./readme_files/examples_report_first_run.png)
84
61
 
85
- RSpec Tracer requires **Ruby 2.5+** and **rspec-core >= 3.6.0**. To use with **Rails 5+**,
86
- make sure to use **rspec-rails >= 4.0.0**. If you are using SimpleCov, it is
87
- recommended to use **simplecov >= 0.12.0**.
62
+ **Next Run**
88
63
 
89
- ### Additional Tools
64
+ ![](./readme_files/examples_report_next_run.png)
90
65
 
91
- To use RSpec Tracer on CI, you need to have an **S3 bucket** and
92
- **[AWS CLI](https://aws.amazon.com/cli/)** installed.
66
+ ### Flaky Examples Report
93
67
 
94
- ## Getting Started
68
+ These reports provide flaky tests information. Assuming **the following two tests
69
+ failed in the first run.**
95
70
 
96
- 1. **Load and Start RSpec Tracer**
71
+ **Next Run**
97
72
 
98
- - **With SimpleCov**
73
+ ![](./readme_files/flaky_examples_report_first_run.png)
99
74
 
100
- If you are using `SimpleCov`, load RSpec Tracer right after the SimpleCov load
101
- and launch:
75
+ **Another Run**
102
76
 
103
- ```ruby
104
- require 'simplecov'
105
- SimpleCov.start
77
+ ![](./readme_files/flaky_examples_report_next_run.png)
106
78
 
107
- # Load RSpec Tracer
108
- require 'rspec_tracer'
109
- RSpecTracer.start
110
- ```
79
+ ### Examples Dependency Report
111
80
 
112
- Currently using RSpec Tracer with SimpleCov has the following two limitations:
113
- - SimpleCov **won't be able to provide branch coverage report** even when enabled.
114
- - RSpec Tracer **nullifies the `SimpleCov.at_exit`** callback.
81
+ These reports show a list of dependent files for each test.
115
82
 
116
- - **Without SimpleCov**
83
+ ![](./readme_files/examples_dependency_report.png)
117
84
 
118
- Load and launch RSpec Tracer at the very top of `spec_helper.rb` (or `rails_helper.rb`,
119
- `test/test_helper.rb`). Note that `RSpecTracer.start` must be issued **before loading
120
- any of the application code.**
85
+ ### Files Dependency Report
121
86
 
122
- ```ruby
123
- # Load RSpec Tracer
124
- require 'rspec_tracer'
125
- RSpecTracer.start
126
- ```
87
+ These reports provide information on the total number of tests that will run after changing this particular file.
127
88
 
128
- 2. To enable RSpec Tracer to share cache between different builds on CI, update the
129
- Rakefile in your project to have the following:
89
+ ![](./readme_files/files_dependency_report.png)
130
90
 
131
- ```ruby
132
- spec = Gem::Specification.find_by_name('rspec-tracer')
133
91
 
134
- load "#{spec.gem_dir}/lib/rspec_tracer/remote_cache/Rakefile"
135
- ```
136
- 3. Before running tests, download the remote cache using the following rake task:
92
+ ## Getting Started
137
93
 
138
- ```sh
139
- bundle exec rake rspec_tracer:remote_cache:download
94
+ 1. Add this line to your `Gemfile` and `bundle install`:
95
+ ```ruby
96
+ gem 'rspec-tracer', '~> 0.7', group: :test, require: false
140
97
  ```
141
- 4. Run the tests with RSpec using `bundle exec rspec`.
142
- 5. After running tests, upload the local cache using the following rake task:
143
98
 
144
- ```sh
145
- bundle exec rake rspec_tracer:remote_cache:upload
99
+ And, add the followings to your `.gitignore`:
146
100
  ```
147
- 6. After running your tests, open `rspec_tracer_report/index.html` in the
148
- browser of your choice.
149
-
150
- ## Environment Variables
151
-
152
- To get better control on execution, you can use the following environment variables
153
- whenever required.
154
-
155
- ### BUNDLE_PATH
156
-
157
- Since the bundler uses a vendor directory inside the project, it might cause slowness
158
- depending on the vendor size. You can configure the bundle path outside of the project
159
- using `BUNDLE_PATH` environment variable, for example, `BUNDLE_PATH=$HOME/vendor/bundle`.
160
- Make sure to cache this directory in the CI configuration.
161
-
162
- ### CI
163
-
164
- Mostly all the CI have `CI=true`. If not, you should explicitly set it to `true`.
165
-
166
- ### LOCAL_AWS
167
-
168
- In case you want to test out the caching feature in the local development environment.
169
- You can install [localstack](https://github.com/localstack/localstack) and
170
- [awscli-local](https://github.com/localstack/awscli-local) and then invoke the
171
- rake tasks with `LOCAL_AWS=true`.
172
-
173
- ### RSPEC_TRACER_NO_SKIP
174
-
175
- The default value is `false.` If set to `true`, the RSpec Tracer will not skip
176
- any tests. Note that it will continue to maintain cache files and generate reports.
101
+ /rspec_tracer_cache/
102
+ /rspec_tracer_coverage/
103
+ /rspec_tracer_report/
104
+ ```
105
+ 2. Load and launch RSpec Tracer at the very top of `spec_helper.rb` (or `rails_helper.rb`,
106
+ `test/test_helper.rb`). Note that `RSpecTracer.start` must be issued **before loading
107
+ any of the application code.**
177
108
 
178
- ```ruby
179
- RSPEC_TRACER_NO_SKIP=true bundle exec rspec
180
- ```
109
+ ```ruby
110
+ # Load RSpec Tracer
111
+ require 'rspec_tracer'
112
+ RSpecTracer.start
113
+ ```
181
114
 
182
- ### RSPEC_TRACER_S3_URI
115
+ **If you are using SimpleCov**, load RSpec Tracer right after the SimpleCov load
116
+ and launch:
183
117
 
184
- You should provide the S3 bucket path to store the cache files.
118
+ ```ruby
119
+ require 'simplecov'
120
+ SimpleCov.start
185
121
 
186
- ```ruby
187
- export RSPEC_TRACER_S3_URI=s3://ci-artifacts-bucket/rspec-tracer-cache
188
- ```
122
+ # Load RSpec Tracer
123
+ require 'rspec_tracer'
124
+ RSpecTracer.start
125
+ ```
189
126
 
190
- ### RSPEC_TRACER_UPLOAD_LOCAL_CACHE
127
+ Currently using RSpec Tracer with SimpleCov has the following two limitations:
191
128
 
192
- By default, RSpec Tracer does not upload local cache files. You can set this
193
- environment variable to `true` to upload the local cache to S3.
129
+ - SimpleCov **won't be able to provide branch coverage report** even when enabled.
130
+ - RSpec Tracer **nullifies the `SimpleCov.at_exit`** callback.
194
131
 
195
- ### TEST_SUITES
132
+ 3. After running your tests, open `rspec_tracer_report/index.html` in the browser
133
+ of your choice.
196
134
 
197
- Set this environment variable when using test suite id. It determines the total
198
- number of different test suites you are running.
135
+ ## Configuring CI Caching
199
136
 
137
+ To enable RSpec Tracer to share cache between different builds on CI, update the
138
+ Rakefile in your project to have the following:
200
139
  ```ruby
201
- export TEST_SUITES=8
202
- ```
203
-
204
- ### TEST_SUITE_ID
140
+ spec = Gem::Specification.find_by_name('rspec-tracer')
205
141
 
206
- If you have a large set of tests to run, it is recommended to run them in
207
- separate groups. This way, RSpec Tracer is not overwhelmed with loading massive
208
- cached data in the memory. Also, it generates and uses cache for specific test suites
209
- and not merge them.
210
-
211
- ```ruby
212
- TEST_SUITE_ID=1 bundle exec rspec spec/models
213
- TEST_SUITE_ID=2 bundle exec rspec spec/helpers
142
+ load "#{spec.gem_dir}/lib/rspec_tracer/remote_cache/Rakefile"
214
143
  ```
215
144
 
216
- If you run parallel builds on the CI, you should specify the test suite ID and
217
- the total number of test suites when downloading the cache files.
218
-
145
+ Before running tests, download the remote cache using the following rake task:
219
146
  ```sh
220
- $ TEST_SUITES=5 TEST_SUITE_ID=1 bundle exec rake rspec_tracer:remote_cache:download
147
+ bundle exec rake rspec_tracer:remote_cache:download
221
148
  ```
222
149
 
223
- In this case, the appropriate cache should have all the cache files available on
224
- the S3 for each test suite, not just for the current one. Also, while uploading,
225
- make sure to provide the test suite id.
226
-
150
+ After running tests, upload the local cache using the following rake task:
227
151
  ```sh
228
- $ TEST_SUITE_ID=1 bundle exec rake rspec_tracer:remote_cache:upload
152
+ bundle exec rake rspec_tracer:remote_cache:upload
229
153
  ```
230
154
 
231
- ## Sample Reports
232
-
233
- You get the following three reports:
234
-
235
- ### Examples
155
+ You must set the following two environment variables:
236
156
 
237
- These reports provide basic test information:
157
+ - **`GIT_BRANCH`** is the git branch name you are running the CI build on.
158
+ - **`RSPEC_TRACER_S3_URI`** is the S3 bucket path to store the cache files.
159
+ ```sh
160
+ export RSPEC_TRACER_S3_URI=s3://ci-artifacts-bucket/rspec-tracer-cache
161
+ ```
238
162
 
239
- **First Run**
240
-
241
- ![](./readme_files/examples_report_first_run.png)
242
-
243
- **Next Run**
244
-
245
- ![](./readme_files/examples_report_next_run.png)
246
-
247
- ### Flaky Examples
248
-
249
- These reports provide flaky tests information. Assuming **the following two tests
250
- failed in the first run.**
251
-
252
- **Next Run**
253
-
254
- ![](./readme_files/flaky_examples_report_first_run.png)
255
-
256
- **Another Run**
257
-
258
- ![](./readme_files/flaky_examples_report_next_run.png)
259
-
260
- ### Examples Dependency
261
-
262
- These reports show a list of dependent files for each test.
263
-
264
- ![](./readme_files/examples_dependency_report.png)
265
-
266
- ### Files Dependency
267
-
268
- These reports provide information on the total number of tests that will run after changing this particular file.
269
-
270
- ![](./readme_files/files_dependency_report.png)
271
-
272
- ## Configuring RSpec Tracer
163
+ ## Advanced Configuration
273
164
 
274
165
  Configuration settings can be applied in three formats, which are completely equivalent:
275
166
 
276
167
  - The most common way is to configure it directly in your start block:
277
-
278
- ```ruby
279
- RSpecTracer.start do
280
- config_option 'foo'
281
- end
282
- ```
168
+ ```ruby
169
+ RSpecTracer.start do
170
+ config_option 'foo'
171
+ end
172
+ ```
283
173
  - You can also set all configuration options directly:
284
-
285
- ```ruby
286
- RSpecTracer.config_option 'foo'
287
- ```
174
+ ```ruby
175
+ RSpecTracer.config_option 'foo'
176
+ ```
288
177
 
289
178
  - If you do not want to start tracer immediately after launch or want to add
290
179
  additional configuration later on in a concise way, use:
180
+ ```ruby
181
+ RSpecTracer.configure do
182
+ config_option 'foo'
183
+ end
184
+ ```
291
185
 
292
- ```ruby
293
- RSpecTracer.configure do
294
- config_option 'foo'
295
- end
296
- ```
186
+ The available configuration options are:
297
187
 
298
- ## Filters
188
+ - **`root dir`** to set the project root. The default value is the current working
189
+ directory.
190
+ - **`add_filter filter`** to apply [filters](#filters) on the source files to
191
+ exclude them from the dependent files list.
192
+ - **`filters.clear`** to remove the default configured dependent files filters.
193
+ - **`add_coverage_filter filter`** to apply [filters](#filters) on the source files
194
+ to exclude them from the coverage report.
195
+ - **`coverage_filters.clear`** to remove the default configured coverage files filters.
196
+ - **`coverage_track_files glob`** to include files in the given glob pattern in
197
+ the coverage report if these files are not already present.
299
198
 
300
- RSpec Tracer supports two types of filters:
199
+ ```ruby
200
+ RSpecTracer.start do
201
+ # Configure project root
202
+ root '/tmp/my_project'
301
203
 
302
- - To exclude selected files from the dependency list of tests:
204
+ # Clear existing filters
205
+ filters.clear
206
+ # Add dependent files filter
207
+ add_filter %r{^/tasks/}
303
208
 
304
- ```ruby
305
- RSpecTracer.start do
306
- add_filter %r{^/helpers/}
307
- end
308
- ```
309
- - To exclude selected files from the coverage data. You should only use this
310
- when not using SimpleCov.
209
+ # Clear existing coverage filters
210
+ coverage_filters.clear
211
+ # Add coverage files filter
212
+ add_coverage_filter %w[/features/ /spec/ /tests/]
311
213
 
312
- ```ruby
313
- RSpecTracer.start do
314
- add_coverage_filter %r{^/tasks/}
315
- end
316
- ```
214
+ # Define glob to track files in the coverage report
215
+ coverage_track_files '{app,lib}/**/*.rb'
216
+ end
217
+ ```
218
+
219
+ You can configure the RSpec Tracer reports directories using the following environment
220
+ variables:
221
+
222
+ - **`RSPEC_TRACER_CACHE_DIR`** to update the default cache directory (`rspec_tracer_cache`).
223
+ ```sh
224
+ export RSPEC_TRACER_CACHE_DIR=/tmp/rspec_tracer_cache
225
+ ```
226
+ - **`RSPEC_TRACER_COVERAGE_DIR`** to update the default coverage directory (`rspec_tracer_coverage`).
227
+ ```sh
228
+ export RSPEC_TRACER_CACHE_DIR=/tmp/rspec_tracer_coverage
229
+ ```
230
+ - **`RSPEC_TRACER_REPORT_DIR`** to update the default html reports directory (`rspec_tracer_report`).
231
+ ```sh
232
+ export RSPEC_TRACER_CACHE_DIR=/tmp/rspec_tracer_report
233
+ ```
234
+
235
+ These settings are available through environment variables because the rake tasks
236
+ to download and upload the cache files need to use the same directories.
237
+
238
+ ## Filters
317
239
 
318
- By default, a filter is applied that removes all files OUTSIDE of your project's
319
- root directory - otherwise you'd end up with the source files in the gems you are
320
- using as tests dependency.
240
+ By default, RSpec Tracer ignores all the files outside of the project root directory -
241
+ otherwise you would end up with the source files in the gems you are using in the
242
+ project. It also applies the following filters:
243
+ ```ruby
244
+ RSpecTracer.configure do
245
+ add_filter '/vendor/bundle/'
246
+
247
+ add_coverage_filter %w[
248
+ /autotest/
249
+ /features/
250
+ /spec/
251
+ /test/
252
+ /vendor/bundle/
253
+ ].freeze
254
+ end
255
+ ```
321
256
 
322
257
  ### Defining Custom Filteres
323
258
 
@@ -369,6 +304,42 @@ end
369
304
 
370
305
  You can pass in an array containing any of the other filter types.
371
306
 
307
+ ## Environment Variables
308
+
309
+ To get better control on execution, you can use the following environment variables
310
+ whenever required.
311
+
312
+ - **`LOCAL_AWS (default: false)`:** In case you want to test out the caching feature in the local
313
+ development environment. You can install [localstack](https://github.com/localstack/localstack)
314
+ and [awscli-local](https://github.com/localstack/awscli-local) and then invoke the
315
+ rake tasks with `LOCAL_AWS=true`.
316
+
317
+ - **`RSPEC_TRACER_NO_SKIP (default: false)`:** Use this environment variables to
318
+ not skip any tests. Note that it will continue to maintain cache files and generate
319
+ reports.
320
+
321
+ - **`RSPEC_TRACER_UPLOAD_LOCAL_CACHE (default: false)`:** By default, RSpec Tracer
322
+ does not upload local cache files. You can set this environment variable to `true`
323
+ to upload the local cache to S3.
324
+
325
+ - **`RSPEC_TRACER_VERBOSE (default: false)`:** To print the intermediate steps
326
+ and time taken, use this environment variable.
327
+
328
+ - **`TEST_SUITES`:** Set this environment variable when running parallel builds
329
+ in the CI. It determines the total number of different test suites you are running.
330
+ ```sh
331
+ export TEST_SUITES=8
332
+ ```
333
+
334
+ - **`TEST_SUITE_ID`:** If you have a large set of tests to run, it is recommended
335
+ to run them in separate groups. This way, RSpec Tracer is not overwhelmed with
336
+ loading massive cached data in the memory. Also, it generates and uses cache for
337
+ specific test suites and not merge them.
338
+ ```sh
339
+ TEST_SUITE_ID=1 bundle exec rspec spec/models
340
+ TEST_SUITE_ID=2 bundle exec rspec spec/helpers
341
+ ```
342
+
372
343
  ## Contributing
373
344
 
374
345
  Read the [contribution guide](https://github.com/avmnu-sng/rspec-tracer/blob/main/.github/CONTRIBUTING.md).