|
| 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) |
0 commit comments