makandra / geordi

Collection of command line tools used in our daily work with Ruby, Rails and Linux.
https://makandra.com/
MIT License
104 stars 16 forks source link

Improve flexibilty of `geordi tests` #216

Closed makmic closed 2 months ago

makmic commented 4 months ago

The current implementation of geordi tests looks like this:

def tests(*args)
  if args.any?
    args, opts = Thor::Options.split(args)
    error_message = "When passing arguments, the first argument must be either an RSpec or a Cucumber path."

    if args.empty?
      Interaction.fail error_message
    elsif args.first.start_with? 'spec'
      invoke 'rspec', args, opts
    elsif args.first.start_with? 'features'
      invoke 'cucumber', args, opts
    else
      Interaction.fail error_message
    end
  # ...
end

I wanted to run a command like this, which is not currently possible:

geordi test ./spec/config/i18n_spec.rb features/translation.feature

As we're using GitLab which offers a quite practical copy failed tests button, I'd really be looking forward to support its output with the geordi tests command.

A possible implementation could look like this (untested!):

def tests(*args)
  if args.any?
    args, opts = Thor::Options.split(args)
    rspec_paths = []
    cucumber_paths = []

    args.each do |spec_path|
      if spec_path.end_with?('.feature')
        cucumber_paths << spec_path
      elsif spec_path.end_with?('_spec.rb')
        rspec_paths << spec_path
      else
        return Interaction.fail "When passing arguments, each argument must be either be a RSpec or a Cucumber path."
      end
    end

    if opts.any? && rspec_paths.any? && cucumber_paths.any?
      Interaction.fail "Cannot mix specs and features while passing RSpec or Cucumber CLI flags - we're unable to guess which CLI option belongs to which test runner."
    else
      invoke 'rspec', rspec_paths, opts if rspec_paths.any?
      invoke 'cucumber', cucumber_paths, opts if cucumber_paths.any?
    end
  # ...
end

WDYT?

codener commented 4 months ago

Talked to @makmic. He just wants to be able to run all failed CI-tests locally with minimum effort.

Since we already have this command in place, adding this seems reasonable to me. Implementation notes:

We should add hints about this command to the cucumber and rspec commands. Like "geordi tests takes mixed RSpec and Cucumber paths and runs both. Useful when copying failed tests from a CI run."

I'll discuss this with the team.

codener commented 1 month ago

Released as 10.1.0.