Class: Routes2spec::Command

Inherits:
Rails::Command::Base
  • Object
show all
Defined in:
lib/routes2spec/command.rb

Overview

Routes2spec::Command class

Constant Summary collapse

SUPPORTED_VERBS =
Routes2spec::RequestSpecFormatter::SUPPORTED_VERBS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.executableObject



28
29
30
# File 'lib/routes2spec/command.rb', line 28

def executable
  "routes2spec"
end

Instance Method Details

#performObject Also known as: routes2spec



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
# File 'lib/routes2spec/command.rb', line 33

def perform(*)
  if options.version?
    say "Routes2spec: #{Routes2spec::VERSION}"
    exit 0
  end

  if options.binstubs?
    make_binstubs
    exit 0
  end

  if options.verb? && !SUPPORTED_VERBS.include?(options.verb&.downcase)
    say "Specified verb(#{options.verb}) is not supported! Supported verbs: [#{SUPPORTED_VERBS.join(", ")}]"
    exit 1
  end

  require_application_and_environment!
  require "action_dispatch/routing/inspector"

  results = inspector.format(formatter, routes_filter)
  results.each do |result|
    relative_path = File.join("spec/requests", *result[:namespaces], "#{result[:name].underscore}_spec.rb")
    writing_file(relative_path, result[:content])

    relative_path = File.join("spec/routing", *result[:namespaces], "#{result[:name].underscore}_spec.rb")
    writing_file(relative_path, result[:routing_content]) if options.routing?
  end
end