Skip to content

Commit 7ecc931

Browse files
committed
docs(predict): explain how it works
1 parent 20c3c51 commit 7ecc931

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

docusaurus/docs/ruby/predict.mdx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,39 @@ A substantial percentage of your CI builds is spent running tests that would nev
2525

2626
PREDICT runs only the tests that are likely to fail. The subset of tests is calculated by combining the test code coverage collected over time with the changes you are working on.
2727

28+
## How it works
29+
30+
PREDICT collects test coverage into a report that looks like the following:
31+
32+
```json
33+
{
34+
"spec/models/user_spec.rb[1:1]": [
35+
"app/models/user.rb"
36+
],
37+
"spec/features/dashboard_spec.rb[1:1:1]": [
38+
"app/models/user.rb",
39+
"app/models/organization.rb",
40+
"app/controllers/application_controller.rb",
41+
"app/controllers/dashboard_controller.rb",
42+
"app/views/dashboard/index.html.erb"
43+
]
44+
}
45+
```
46+
47+
The test prediction is based on the following steps:
48+
1. Fetch from the API the most recent test coverage report
49+
1. Calculate what files changed between the current commit and the commit that generated the report
50+
1. Find in the report which test examples cover the changed files
51+
52+
For example, if `app/models/user.rb` changed, PREDICT would run:
53+
- `spec/models/user_spec.rb[1:1]`
54+
- `spec/features/dashboard_spec.rb[1:1:1]`
55+
56+
If `app/views/dashboard/index.html.erb` changed instead, PREDICT would only run:
57+
- `spec/features/dashboard_spec.rb[1:1:1]`
58+
59+
## Configuration
60+
2861
To enable PREDICT, set any of the following ENV variables:
2962

3063
* `KNAPSACK_PRO_PREDICT_DISABLED_ON_BRANCHES` (comma-separated strings or regular expressions): on what branches to run all the tests
@@ -38,7 +71,7 @@ Given the dynamic nature of Ruby, PREDICT will likely not be correct 100% of the
3871
* Include `[skip predict]` / `[predict skip]` in the last commit message before you merge a pull request
3972
* Include your production branch in `KNAPSACK_PRO_PREDICT_DISABLED_ON_BRANCHES`
4073

41-
## **Example**
74+
### Example
4275

4376
Given the following configuration on CI:
4477

@@ -57,7 +90,7 @@ You can expect the following behaviour:
5790
* The current commit message contains `[skip predict]` / `[predict skip]`
5891
* The per-test coverage does not exist on the Knapsack Pro API (e.g., you just enabled PREDICT)
5992

60-
## Ruby glob
93+
### Ruby glob
6194

6295
Both `KNAPSACK_PRO_PREDICT_DISABLED_ON_CHANGED_FILES` and `KNAPSACK_PRO_PREDICT_ALWAYS_RUN_TESTS` accept a Ruby glob as a value.
6396

0 commit comments

Comments
 (0)