toptal / crystalball

Regression Test Selection library for your RSpec test suite

Home Page:https://toptal.github.io/crystalball/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Watch mode

pirj opened this issue · comments

Add a --watch that would run tests as Crystalball finds the changes in the source code.

  • Use guard (or similar)
  • Lookup needs to be faster
  • Only run fast specs
  • Support --fail-fast
  • Have a predictor for a single file
    • Right now it only works with the git diff

It's a very useful feature and will be great to have official support. My current setup is using a shell script which is committing any Guard detected changes to temp git branch.
Will be great to abstract out GitRepo and SourceDiff so changed files may be provided from the different input sources like crystalball command arguments.

# Gemfile
group :test do
  gem 'crystalball'
  gem 'guard-rspec'
end
# Guardfile
group :spec do
  require 'guard/compat/plugin'

  SPEC_DIRS = ENV.fetch('SPEC_DIRS', 'spec').split

  Guard::Compat::UI.info("spec_paths are #{SPEC_DIRS}")
  common_options = {
    all_on_start: true,
    spec_paths: SPEC_DIRS
  }

  crystalball_options = common_options.merge(
    cmd: 'bundle exec crystalball',
    run_all: { cmd: 'CRYSTALBALL=true bundle exec rspec' },
    failed_mode: :focus
  )

  git_options = common_options.merge(
    cmd: './script/commit_changes.sh', 
    run_all: { cmd: './script/reset_temp_branch.sh' }
  )

  guard :rspec, git_options do
    ...
  end

  guard :rspec, crystalball_options do
    ...
  end
end
# config/crystalball.yml
diff_from: 'origin/temp-crystalball'
# script/commit_changes.sh
#!/bin/bash

# fetch last parameter
shift $(($# - 1))
CHANGESET="$1"

pushd ../temp-crystalball
git reset --hard master
git add $CHANGESET
git commit -m "commit file $CHANGESET"
git push -f origin temp-crystalball
popd

git fetch origin

# simulate RSpec output
cat <<-CONTENT >../tmp/rspec_guard_result
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="rspec" tests="0" skipped="0" failures="0" errors="0" time="0.000580" timestamp="2019-08-21T19:08:55+00:00" hostname="989952f29f49">
<properties>
<property name="seed" value="52324"/>
</properties>
</testsuite>
CONTENT

Related to #101