22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/generators/rspec/endpoint/endpoint_generator.rb', line 22
def copy_files
Rails.application.load_tasks
routes = capture_output { Rake::Task['routes'].invoke }
@route = routes.split("\n").grep(Regexp.new "#{class_path.join('/')}##{file_name}").first || raise("#{class_path.join('/')}##{file_name} not found in routes")
@http_verb = @route[/GET|POST|DELETE|PUT|PATCH/]
@path = @route[/(\/.*)\(/, 1]
@path_params = @path.split('/').select{|i| i[/:/]}
@path_params.each do |param|
@path.sub!(param, '#{' + param[1..-1] + '}')
end
if behavior == :revoke
template 'action_request_spec.rb', "spec/requests/#{file_path}_spec.rb"
elsif behavior == :invoke
empty_directory Pathname.new('spec/requests').join(*class_path)
template 'action_request_spec.rb', "spec/requests/#{file_path}_spec.rb"
end
end
|