Class: Railstest::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/railstest/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



11
12
13
# File 'lib/railstest/cli.rb', line 11

def initialize(args)
  @args = args.dup
end

Class Method Details

.start(args = ARGV) ⇒ Object



7
8
9
# File 'lib/railstest/cli.rb', line 7

def self.start(args = ARGV)
  new(args).run
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/railstest/cli.rb', line 15

def run
  options = {
    ruby_version: nil,
    rails_version: nil,
    database: nil,
    test_path: nil,
    gem_path: nil,
    workers: 1,
    gemspec: false
  }

  parser = OptionParser.new do |opts|
    opts.banner = "Railstest CLI\nUsage: railstest [options]"
    opts.separator ''
    opts.separator 'Options:'

    opts.on('--ruby VERSION', 'Ruby version filter (tests all compatible Rails when --rails omitted)') do |v|
      options[:ruby_version] = v
    end

    opts.on('--rails VERSION', 'Rails version filter (tests all compatible Ruby when --ruby omitted)') do |v|
      options[:rails_version] = normalize_rails_version(v)
    end

    opts.on('--db DATABASE', 'Database: sqlite, mysql, postgres (default: sqlite)') do |db|
      options[:database] = db
    end

    opts.on('--path PATH', 'Specific test file or directory') do |path|
      options[:test_path] = path
    end

    opts.on('--gem-path PATH', 'Path to the gem to test') do |path|
      options[:gem_path] = path
    end

    opts.on('--gemspec', 'Show which combinations the gemspec claims to support (no Docker required)') do
      options[:gemspec] = true
    end

    opts.on('-j N', '--workers N', Integer, 'Parallel workers (default: 1, sequential)') do |n|
      options[:workers] = n
    end

    opts.separator ''

    opts.on('-v', '--version', 'Show version') do
      puts "railstest #{Railstest::VERSION}"
      exit
    end

    opts.on('-h', '--help', 'Show this help') do
      puts opts
      exit
    end
  end

  parser.parse!(@args)

  base_path = options[:gem_path] || Dir.pwd
  gem_name = detect_gem_name(base_path)

  if options[:gemspec]
    show_gemspec_matrix(options, gem_name)
    return
  end

  # Single combination: both versions explicitly given
  if options[:ruby_version] && options[:rails_version]
    run_single(options, gem_name)
  else
    run_combinations(options, gem_name)
  end
rescue Railstest::Error => e
  puts "Error: #{e.message}"
  exit 1
end