knapsack_pro ruby gem

Knapsack Pro

Speed up your tests

Run your 1-hour test suite in 2 minutes with optimal parallelisation on your existing CI infrastructure


Circle CI Gem Version



Knapsack Pro wraps your current test runner(s) and works with your existing CI infrastructure to parallelize tests optimally:

  • Dynamically splits your tests based on up-to-date test execution data
  • Is designed from the ground up for CI and supports all of them
  • Tracks your CI builds to detect bottlenecks
  • Does not have access to your source code and collects minimal test data (with opt-in encryption)
  • Enables you to export historical metrics about your CI builds
  • Supports out-of-the-box any Ruby test runners, Cypress, Jest (and provides both SDK and API to integrate with any other language)
  • Replaces local dependencies like Redis with an API and runs your tests regardless of network problems

The knapsack_pro gem supports all CIs and the following test runners:

  • RSpec
  • Cucumber
  • Minitest
  • test-unit
  • Spinach
  • Turnip

Installation

The Installation Guide will ask you a few questions and generate instruction steps for your project:

Install button

Upgrade

Knapsack Pro follows semantic versioning, but make sure to check the changelog before updating gem with:

bundle update knapsack_pro

Contributing

Testing

RSpec:

bin/test

Scripted tests can be found in the Rails App With Knapsack Pro repository.

Distroless Container Images

Ensure that Knapsack Pro is written in a way that supports Distroless Container Images. Avoid using a shell when calling methods like Kernel.system or Kernel.exec.

✅ Good - shell is not required

cmd = 'bundle exec rake knapsack_pro:something'
Kernel.system({ 'RAILS_ENV' => 'test' }, cmd)

cmd = ['bundle', 'exec', 'rake', 'knapsack_pro:example']
Kernel.system({ 'RAILS_ENV' => 'test' }, *cmd)

⛔️ Bad - shell is required

# Avoid embedding environment variables in the command string
cmd = 'RAILS_ENV=test bundle exec rake knapsack_pro:something'
Kernel.system(cmd)

# Avoid output redirection
cmd = 'program 2>/dev/null'
Kernel.system(cmd)

# Avoid using the pipe operator
cmd = 'program1 | program2'
Kernel.system(cmd)

Use Dockerfile to test if the code requires a shell:

docker build -t test -f distroless/Dockerfile . && docker run --rm -it test

Publishing

  1. Move the changes listed in the UNRELEASED section of the CHANGELOG.md to the proper version

  2. Update the gem version in lib/knapsack_pro/version.rb

  3. git commit -am "Bump version x.x.x"

  4. Build, tag, push, release: bundle exec rake release

  5. Update the latest available gem version in TestSuiteClientVersionChecker for the Knapsack Pro API repository.

  6. Update the knapsack_pro gem version in: