class Cardio::Command::RspecCommand::Parser

parse decko/card -specific options for RSpec

Constants

DESC
RSPEC_BANNER
RSPEC_PATH_MESSAGE

Public Class Methods

new(opts) click to toggle source
Calls superclass method
# File lib/cardio/command/rspec_command/parser.rb, line 35
def initialize opts
  super() do |parser|
    parser.banner = RSPEC_BANNER
    parser.separator RSPEC_PATH_MESSAGE

    file_options parser, opts
    other_options parser, opts
    parser.separator "\n"
  end
end

Private Instance Methods

file_options(parser, opts) click to toggle source
# File lib/cardio/command/rspec_command/parser.rb, line 48
def file_options parser, opts
  parser.on("-d", "--spec FILENAME(:LINE)", DESC[:d]) do |file|
    opts[:files] = find_spec_file(file, "#{Decko.root}/mod")
  end
  parser.on("-m", "--mod MODNAME", DESC[:m]) do |file|
    opts[:files] = find_mod_file(file, Cardio.gem_root)
  end
  parser.on("-c", "--core-spec FILENAME(:LINE)", DESC[:c]) do |file|
    opts[:files] = find_spec_file(file, Cardio.gem_root)
  end
end
find_matching_spec_files(file, line, base_dir) click to toggle source
# File lib/cardio/command/rspec_command/parser.rb, line 113
def find_matching_spec_files file, line, base_dir
  file = File.basename(file, ".rb").sub(/_spec$/, "")
  Dir.glob("#{base_dir}/**/#{file}_spec.rb").flatten.map do |spec_file|
    line ? "#{spec_file}:#{line}" : file
  end.join " "
end
find_mod_file(filename, base_dir) click to toggle source
# File lib/cardio/command/rspec_command/parser.rb, line 92
def find_mod_file filename, base_dir
  # FIXME: - use Cardio::Mod lookup

  if File.exist?("mod/#{filename}") || File.exist?("#{base_dir}/mod/#{filename}")
    "#{base_dir}/mod/#{filename}"
  elsif (files = find_spec_file(filename, "mod"))&.present?
    files
  else
    find_spec_file(file, "#{base_dir}/mod")
  end
end
find_spec_file(filename, base_dir) click to toggle source
# File lib/cardio/command/rspec_command/parser.rb, line 104
def find_spec_file filename, base_dir
  file, line = filename.split(":")
  if file.include?("_spec.rb") && File.exist?(file)
    filename
  else
    find_matching_spec_files file, line, base_dir
  end
end
other_options(parser, opts) click to toggle source
# File lib/cardio/command/rspec_command/parser.rb, line 60
def other_options parser, opts
  parser.on("-s", "--[no-]simplecov", "Run with simplecov") do |s|
    opts[:simplecov] = s
  end
  parser.on("--rescue", "Run with pry-rescue") do
    process_rescue_opts opts
  end
  parser.on("--[no-]spring", "Run with spring") do |spring|
    process_spring_opts spring, opts
  end
end
process_rescue_opts(opts) click to toggle source
# File lib/cardio/command/rspec_command/parser.rb, line 72
def process_rescue_opts opts
  if opts[:executer] == "spring"
    puts "Disabled pry-rescue. Not compatible with spring."
  else
    opts[:rescue] = "rescue "
  end
end
process_spring_opts(spring, opts) click to toggle source
# File lib/cardio/command/rspec_command/parser.rb, line 80
def process_spring_opts spring, opts
  if spring
    opts[:executer] = "spring"
    if opts[:rescue]
      opts[:rescue] = ""
      puts "Disabled pry-rescue. Not compatible with spring."
    end
  else
    opts[:executer] = "bundle exec"
  end
end