### Setup Development Dependencies Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/README.md Run this command after cloning the repository to install necessary dependencies for development. ```bash bin/setup ``` -------------------------------- ### Install Crystalball via Bundler Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/README.md After adding the gem to your Gemfile, run this command to install it. ```bash bundle install ``` -------------------------------- ### Start Interactive Console Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/README.md Use this command to launch an interactive Ruby console for experimenting with the gem. ```bash bin/console ``` -------------------------------- ### Install Gem Locally Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/README.md Run this command to install the Crystalball gem onto your local machine. ```bash bundle exec rake install ``` -------------------------------- ### Install Crystalball via gem install Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/README.md Alternatively, you can install the Crystalball gem directly using the gem install command. ```bash gem install crystalball ``` -------------------------------- ### Start Crystalball MapGenerator Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/index.md Start the MapGenerator in your `spec_helper` before loading any application files. This configuration registers the CoverageStrategy for profiling. ```ruby if ENV['CRYSTALBALL'] == 'true' Crystalball::MapGenerator.start! do |config| config.register Crystalball::MapGenerator::CoverageStrategy.new end end ``` -------------------------------- ### Register DescribedClassStrategy Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/map_generators.md The `DescribedClassStrategy` maps examples to the definition paths of their `described_class` and ancestors. It can also accept a custom execution detector. ```ruby Crystalball::MapGenerator.start! do |config| #... config.register Crystalball::MapGenerator::DescribedClassStrategy.new end ``` ```ruby Crystalball::MapGenerator.start! do |config| #... config.register Crystalball::MapGenerator::DescribedClassStrategy.new(my_detector) end ``` -------------------------------- ### Register ActionViewStrategy Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/map_generators.md Integrate Rails-specific strategies by requiring `crystalball/rails`. The `ActionViewStrategy` patches `ActionView::Template#compile!` to map examples to affected views. ```ruby Crystalball::MapGenerator.start! do |config| #... config.register Crystalball::MapGenerator::ActionViewStrategy.new end ``` -------------------------------- ### AssociatedSpecs Strategy Configuration Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/predictors.md Configure the AssociatedSpecs strategy to define rules for detecting which specs should be included in predictions based on file changes. This strategy does not depend on a previously generated example group map. ```ruby predictor.use Crystalball::Predictor::AssociatedSpecs.new( from: %r{models/(.*).rb}, to: "./spec/models/%s_spec.rb" ) ``` -------------------------------- ### Run Tests in Development Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/README.md Execute this command to run the test suite during development. ```bash rake spec ``` -------------------------------- ### Register CoverageStrategy Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/map_generators.md Use `CoverageStrategy` to detect files covered by a spec, indicating potential breakage if changed. Pass a custom detector object that responds to `#detect`. ```ruby Crystalball::MapGenerator.start! do |config| #... config.register Crystalball::MapGenerator::CoverageStrategy.new(my_detector) end ``` -------------------------------- ### Register OneshotCoverageStrategy Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/map_generators.md Utilize `OneshotCoverageStrategy` for more performant coverage tracking. This strategy is not compatible with existing coverage processes and requires starting/clearing coverage between tests. It accepts `exclude_prefixes` to filter paths. ```ruby Crystalball::MapGenerator.start! do |config| #... config.register Crystalball::MapGenerator::OneshotCoverageStrategy.new(exclude_prefixes: %w[vendor/ruby]) end ``` -------------------------------- ### Customize Map Filename Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/map_generators.md Customize the resulting map filename using the `map_storage_path` configuration. This allows for dynamic naming based on environment variables. ```ruby Crystalball::MapGenerator.start! do |config| #... config.map_storage_path = "execution_map_#{ENV['TEST_ENV_NUMBER'].to_i}.yml" end ``` -------------------------------- ### ModifiedSchema Strategy Configuration Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/predictors.md Configure the ModifiedSchema strategy for Rails applications to predict specs affected by database schema changes. Requires a path to a tables map file generated by TablesMapGenerator. ```ruby predictor.use Crystalball::Rails::Predictor::ModifiedSchema.new( tables_map_path: './tables_map.yml' ) ``` -------------------------------- ### Disable Compact Map Output Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/map_generators.md Configure the `MapGenerator` to produce a plain, readable map instead of the default compact format by setting `config.compact_map = false`. ```ruby Crystalball::MapGenerator.start! do |config| #... config.compact_map = false end ``` -------------------------------- ### Add Crystalball to Gemfile Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/README.md Add this line to your application's Gemfile to include Crystalball in your test dependencies. ```ruby group :test do gem 'gitlab-crystalball' end ``` -------------------------------- ### Custom Prediction Builder with Strategies Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/predictors.md Define a custom prediction builder by inheriting from Crystalball::RSpec::PredictionBuilder and overloading the predictor method to include additional strategies like ModifiedSupportSpecs. ```ruby class MyPredictionBuilder < Crystalball::RSpec::PredictionBuilder def predictor super do |p| p.use Crystalball::Predictor::ModifiedSpecs.new p.use Crystalball::Predictor::ModifiedExecutionPaths.new p.use Crystalball::Predictor::ModifiedSupportSpecs.new end end end ``` -------------------------------- ### Customize TablesMapGenerator Filename Source: https://gitlab.com/gitlab-org/ruby/gems/crystalball/-/blob/main/docs/map_generators.md Customize the output filename for `TablesMapGenerator` using `map_storage_path`. This generator is specific to Rails applications for collecting table-to-model mappings. ```ruby Crystalball::TablesMapGenerator.start! do |config| #... config.map_storage_path = 'my_custom_tables_map_name.yml' end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.