Skip to content

Commit 0b078c3

Browse files
committed
docs: predict
1 parent f86e845 commit 0b078c3

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

_plugins/docusaurus.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def system!(*args)
7575
"hooks",
7676
"parallel_tests",
7777
"puffing-billy",
78+
"predict",
7879
"queue-mode",
7980
"reference",
8081
"rspec",

docusaurus/docs/ruby/predict.mdx

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
pagination_next: null
3+
pagination_prev: null
4+
---
5+
6+
# PREDICT
7+
8+
:::caution
9+
10+
This feature is limited to beta-testers.
11+
12+
:::
13+
14+
:::caution
15+
16+
Only Ruby >= 3.2.0 & RSpec are supported.
17+
18+
:::
19+
20+
21+
A substantial percentage of your CI builds is spent running tests that would never fail. For example, updating a README.md should not require any testing. And changing a bunch of files should not run the entire test suite.
22+
23+
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.
24+
25+
To enable PREDICT, set any of the following ENV variables:
26+
27+
* `KNAPSACK_PRO_PREDICT_DISABLED_ON_BRANCHES` (comma-separated list): on what branches to run all the tests
28+
* `KNAPSACK_PRO_PREDICT_DISABLED_ON_CHANGED_FILES` (glob): what files, if modified, cause all the tests to run
29+
* `KNAPSACK_PRO_PREDICT_ALWAYS_RUN_TESTS` (glob): what tests to always run
30+
31+
If PREDICT finds the string `[skip predict]` / `[predict skip]` in the commit message, it will run all the tests.
32+
33+
:::tip
34+
35+
You can expand a glob with:
36+
37+
```bash
38+
ruby -e "puts (Dir.glob 'Gemfile.*')"
39+
40+
# Gemfile
41+
# Gemfile.lock
42+
```
43+
44+
:::
45+
46+
Given the dynamic nature of Ruby, PREDICT will likely not be correct 100% of the time. So we recommend you run all the tests before deploying to production. You can do that in multiple ways:
47+
48+
* Include `[skip predict]` / `[predict skip]` in the last commit message before you merge a pull request
49+
* Include your production branch in `KNAPSACK_PRO_PREDICT_DISABLED_ON_BRANCHES`
50+
51+
## **Example**
52+
53+
Given the following configuration on CI:
54+
55+
```bash
56+
KNAPSACK_PRO_PREDICT_DISABLED_ON_BRANCHES='main,staging' \
57+
KNAPSACK_PRO_PREDICT_DISABLED_ON_CHANGED_FILES='{Gemfile,Gemfile.lock}' \
58+
KNAPSACK_PRO_PREDICT_ALWAYS_RUN_TESTS='spec/features/**/*_spec.rb' \
59+
bin/rake "knapsack_pro:queue:rspec"
60+
```
61+
62+
You can expect the following behaviour:
63+
64+
* On main and staging, all tests are run
65+
* On the other branches, the tests subset is run (including `spec/features/**/*_spec.rb`) unless:
66+
* `Gemfile` or `Gemfile.lock` were modified
67+
* The current commit message contains `[skip predict]` / `[predict skip]`
68+
* The per-test coverage does not exist on the Knapsack Pro API (e.g., just enabled the feature)

docusaurus/sidebars.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ const sidebars: SidebarsConfig = {
7575
label: "Split by test examples",
7676
id: "ruby/split-by-test-examples",
7777
},
78+
{
79+
type: "doc",
80+
label: "PREDICT",
81+
id: "ruby/predict",
82+
className: "hidden",
83+
},
7884
],
7985
},
8086
{

0 commit comments

Comments
 (0)