Skip to content

Latest commit

 

History

History

lefthook+crystalball

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Read this post for more information: Lefthook, Crystalball, and git magic for smooth development experience.

What does this example do

  1. Installs missing gems on git pull or branch checkout.

  2. Applies new database migrations on git pull.

  3. Rollbacks migrations that are present only on some feature branch on checkout from that branch to another.

  4. Runs only relevant part of your test suite (via crystalball gem) on git push, aborts push when the first spec is failed.

  5. Updates crystalball code execution maps once a week.

Installation

Add required gems to your Gemfile and install them with bundle install:

group :test do
  gem "crystalball", require: false
end

group :development do
  gem "git", require: false # it is a dependency of Crystalball, but it is better to declare it explicitly
  gem "lefthook", require: false
end

Copy lefthook configuration file lefthook.yml and directory .lefthook to your project.

Set up Lefthook:

lefthook install

Copy config/crystalball.yml file to your project

Setup your test suite to collect code coverage information:

# spec/spec_helper.rb
if ENV["CRYSTALBALL"] == "true"
  require "crystalball"
  require "crystalball/rails"

  Crystalball::MapGenerator.start! do |config|
    config.register Crystalball::MapGenerator::CoverageStrategy.new
    config.register Crystalball::Rails::MapGenerator::I18nStrategy.new
    config.register Crystalball::MapGenerator::DescribedClassStrategy.new
  end
end

Generate code execution maps:

CRYSTALBALL=true bundle exec rspec

And that’s it!