Skip to content

Instantly share code, notes, and snippets.

@ArturT
Last active December 5, 2023 12:01
Show Gist options
  • Save ArturT/8c901ebfa773fc934a7d30cf1de26558 to your computer and use it in GitHub Desktop.
Save ArturT/8c901ebfa773fc934a7d30cf1de26558 to your computer and use it in GitHub Desktop.
CircleCI rerun failed tests in RSpec with Knapsack Pro Queue Mode. Thanks to that you can rerun only failed tests instead of rerunning the whole CI build. https://docs.knapsackpro.com/ruby/circleci/ & https://knapsackpro.com
- run:
name: Run tests
command: |
export CIRCLE_TEST_REPORTS=/tmp/test-results
mkdir -p $CIRCLE_TEST_REPORTS
# split slow spec files by test examples
# https://docs.knapsackpro.com/ruby/split-by-test-examples/
export KNAPSACK_PRO_RSPEC_SPLIT_BY_TEST_EXAMPLES=true
# Use circleci CLI to find out if we need to run all tests or rerun failed tests
# We are telling circleci to split the tests across 1 node to get the full list of all tests for consideration. We leave the splitting to Knapsack Pro.
export KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE=/tmp/tests_to_run.txt
circleci tests glob "spec/**/*_spec.rb" | circleci tests run --index 0 --total 1 --command ">$KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE xargs -n1 echo" --verbose
# tell Knapsack Pro to run only tests from the file (and still use Knapsack Pro Queue Mode magic)
bundle exec rake "knapsack_pro:queue:rspec[--format documentation --format RspecJunitFormatter --out tmp/rspec.xml]"
@sethherr
Copy link

sethherr commented Dec 4, 2023

Ahhhh. Ok, thanks for explaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment