toptal / crystalball

Regression Test Selection library for your RSpec test suite
https://toptal.github.io/crystalball/
MIT License
322 stars 41 forks source link

[Question] Can I generate a list of tests that need to be performed? #139

Open jeffsaremi opened 1 year ago

jeffsaremi commented 1 year ago

I don't want to run the actual tests using bundle exec crystalball And where the tests are running, there is not git sandbox Instead I'd like to run a command like bundle exec crystalball predict and then get a list of source files or rspec tests that need can be used to run bundle exec rspec ...

Is this possible currently?

SamMolokanov commented 1 year ago

@jeffsaremi

Hello there, one of the possible ways is to define your own runner class which will just send the prediction back to output and then exit. Here is some code:

# custom_runner.rb

class CustomRunner < ::Crystalball::RSpec::Runner

  class << self

    def run(args, err = $stderr, out = $stdout)
      return config["runner_class"].run(args, err, out) unless config["runner_class"] == self

      out.puts(build_prediction)
    end

  end

end

and then use this runner via config:

# crystalball.yml

requires:
  - './custom_runner.rb'

# Custom RSpec runner class to use. Default: 'Crystalball::RSpec::Runner'
runner_class_name: 'CustomRunner'

.....

or (if some flexibility needed) via ENV var:

$ CRYSTALBALL_RUNNER_CLASS_NAME=CustomRunner bundle exec crystalball