Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve flexibilty of geordi tests #216

Closed
makmic opened this issue May 13, 2024 · 2 comments · Fixed by #220
Closed

Improve flexibilty of geordi tests #216

makmic opened this issue May 13, 2024 · 2 comments · Fixed by #220
Assignees

Comments

@makmic
Copy link
Member

makmic commented May 13, 2024

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

  • The code above does not recognise rspec files within ./spec (see .start_with?('spec'))
  • The command does not allow specs and features to be mixed

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
Copy link
Member

codener commented May 17, 2024

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:

  • Instead of start_with? or end_with?, let's use regular expressions like %r{(^|/)features/|\.feature($|:)} and %r{(^|/)spec/|\_spec.rb($|:)}
  • I would not crash, but simply pass options to both test commands. After all, this is a "mixed" command. If it does not work, it will probably fail at the command.
  • It would be nice to have the results summary of both test commands printed last. However, I don't know how this could work. So please at least make sure that the RSpec status is printed after cucumber ran. Like "if rspec_ran then success/fail" after the invocation of cucumber.
  • Remember to update the LONGDESC as well.

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
Copy link
Member

codener commented Jul 23, 2024

Released as 10.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants