routes2spec 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fc17061731dc2153d96ef54d172142c910ea6d3c2015573550adc07f480d08b
4
- data.tar.gz: d3a56701c40d97a9c8408ab1fa8918c869aed151ed8c7fecedf190596f82b9e9
3
+ metadata.gz: 197213dfc7438c267e64f2ad938f57d7e9a48454781e6aabeae8eebba7e6f79c
4
+ data.tar.gz: a963d77704bb92c2177ddd05b1d7fd2053b13df1c54a866597db16a300d72acd
5
5
  SHA512:
6
- metadata.gz: a71c32eea1a488faa670cec692ea8c4394fb168a11418c5cd69873a2533dc8914d54f6fc63080ca96aa5418c412689a6035926960ebc84875e2416c59049749f
7
- data.tar.gz: 1525809ecbb6e2a7f4de27d0f904de0b2ed886f11120a4be8b227ff04e7790ec6cb350d5d19a1b61e9bbca0897d5337d360c3b98c1798cc331454edd9d599f59
6
+ metadata.gz: decf81e5b7aa98f01e6d48b7590f1e6bb6773c7e61f9f65071e303b12ead8f098ab179d627b82fe8c8512a765db0e931ab7366b2eede8675484f77a4666af5c7
7
+ data.tar.gz: cdff45fff6fc5f45cf8e13336e123a0b566fb239b88577afa4991a7a96f6b7e6b1075da88e79373de687ac67e44029d9f9705dc9582568ca7864aad14285776e
data/.rubocop.yml CHANGED
@@ -4,7 +4,7 @@ require:
4
4
  - rubocop-rubycw
5
5
 
6
6
  AllCops:
7
- TargetRubyVersion: 2.7
7
+ TargetRubyVersion: 3.1
8
8
  NewCops: enable
9
9
  DisplayCopNames: true
10
10
  DisplayStyleGuide: true
data/Gemfile CHANGED
@@ -11,3 +11,5 @@ gem "rubocop", "~> 1.21", require: false
11
11
  gem "rubocop-rake", require: false
12
12
  gem "rubocop-rspec", require: false
13
13
  gem "rubocop-rubycw", require: false
14
+
15
+ gem "listen" # for test
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
  Generate Request specs and Routing specs of RSpec, from your Rails routes config.
7
7
  It is useful as a test scaffolding.
8
8
 
9
+ **Currently does not work with Rails 7.**
10
+
9
11
  ## Installation
10
12
 
11
13
  Add this line to your application's Gemfile:
@@ -6,6 +6,8 @@ require_relative "./request_spec_formatter"
6
6
  module Routes2spec
7
7
  # Routes2spec::Command class
8
8
  class Command < Rails::Command::Base
9
+ SUPPORTED_VERBS = Routes2spec::RequestSpecFormatter::SUPPORTED_VERBS
10
+
9
11
  class_option :help, aliases: "-h", banner: "", desc: "Show this message."
10
12
  class_option :version, aliases: "-V", banner: "", desc: "Show version."
11
13
 
@@ -15,10 +17,12 @@ module Routes2spec
15
17
  desc: "Filter by a specific controller, e.g. PostsController or Admin::PostsController."
16
18
  class_option :grep, aliases: "-g", desc: "Grep routes by a specific pattern."
17
19
  class_option :symbol_status, banner: "", desc: "Use symbols for http status."
18
- class_option :overwrite, banner: "", desc: "Overwrite files even if they exist."
19
- class_option :force_overwrite, banner: "", desc: "Force overwrite files even if they exist."
20
+ class_option :literal_path, banner: "", desc: "Use literal paths instead of path helper."
21
+ class_option :overwrite, banner: "", desc: "Prompts for confirmation to overwrite each file if it already exists."
22
+ class_option :force_overwrite, banner: "", desc: "Forcibly overwrites existing files without confirmation."
20
23
  class_option :pending, banner: "", desc: "Mark examples as pending."
21
24
  class_option :routing, type: :boolean, defalut: false, desc: "Generate routing specs."
25
+ class_option :verb, desc: "Generate only specific verb. Supported verbs: [#{SUPPORTED_VERBS.join(", ")}]"
22
26
 
23
27
  class << self
24
28
  def executable
@@ -37,6 +41,11 @@ module Routes2spec
37
41
  exit 0
38
42
  end
39
43
 
44
+ if options.verb? && !SUPPORTED_VERBS.include?(options.verb&.downcase)
45
+ say "Specified verb(#{options.verb}) is not supported! Supported verbs: [#{SUPPORTED_VERBS.join(", ")}]"
46
+ exit 1
47
+ end
48
+
40
49
  require_application_and_environment!
41
50
  require "action_dispatch/routing/inspector"
42
51
 
@@ -107,7 +116,7 @@ module Routes2spec
107
116
  end
108
117
 
109
118
  def formatter_opts
110
- options.symbolize_keys.slice(:symbol_status, :pending)
119
+ options.symbolize_keys.slice(:symbol_status, :literal_path, :pending, :verb)
111
120
  end
112
121
  end
113
122
  end
@@ -3,6 +3,8 @@
3
3
  module Routes2spec
4
4
  # Routes2spec::RequestSpecFormatter class
5
5
  class RequestSpecFormatter
6
+ SUPPORTED_VERBS = %w[get post patch put delete].freeze
7
+
6
8
  STATUS = {
7
9
  get: 200,
8
10
  post: 201,
@@ -57,27 +59,36 @@ module Routes2spec
57
59
  params_str = param_names.map{|name| "#{name}: \"#{name}\"" }.join(", ")
58
60
  path_name = r[:name] || ""
59
61
  path_name = grouped_routes.find{ _1[:path] == r[:path] && !_1[:name].empty? }&.fetch(:name) || "" if path_name.empty?
60
- Routes2spec.log_debug "verb: #{verb}, path: #{path}, path_name: #{path_name}"
62
+ Routes2spec.log_debug "verb: #{verb}, path: #{path}, path_name: #{path_name}, @opts: #{@opts}"
61
63
  if path_name.empty?
62
64
  Routes2spec.log "Skip. No path name! `#{verb&.upcase} #{path}`"
63
65
  next
64
66
  end
65
- unless %w[get post patch put delete].include?(verb)
67
+ unless SUPPORTED_VERBS.include?(verb)
66
68
  Routes2spec.log "Skip. Unsupported verb! `#{verb&.upcase} #{path}`"
67
69
  next
68
70
  end
71
+ if !@opts[:verb].nil? && @opts[:verb].downcase != verb
72
+ Routes2spec.log "Skip. Not matched specified verb(#{@opts[:verb].upcase})! `#{verb&.upcase} #{path}`"
73
+ next
74
+ end
69
75
  endpoint, constraints = r[:reqs].split(" ")
70
76
  Routes2spec.log_debug "endpoint: #{endpoint}, constraints: #{constraints}"
71
77
  # TODO: insert constraints to routing spec
72
78
  status = @opts[:symbol_status] ? SYMBOL_STATUS[verb.to_sym] : STATUS[verb.to_sym]
79
+ use_literal_path = @opts[:literal_path] || false
80
+ path_helper_str = "#{path_name}_path#{params_str.empty? ? "" : "(#{params_str})"}"
81
+ literal_path_str = "\"#{path}\""
82
+ path_str = use_literal_path ? literal_path_str : path_helper_str
73
83
  r.merge(
74
84
  path: path,
85
+ path_str: path_str,
75
86
  path_name: path_name,
76
87
  params_str: params_str,
77
88
  reqs: r[:reqs],
78
89
  endpoint: endpoint,
79
90
  constraints: constraints || "",
80
- status: status
91
+ status: status,
81
92
  )
82
93
  end.compact
83
94
  if routes.empty?
@@ -4,7 +4,7 @@ RSpec.describe "<%= controller_name %>", type: :request do
4
4
  <% routes.each do |route| %>
5
5
  describe "<%= route[:verb].upcase %> <%= route[:path] %>" do
6
6
  it "works!" do
7
- <%= pending ? 'pending "now write some real specs. and remove pending mark."' + "\n " : "" %><%= route[:verb].downcase %> <%= route[:path_name] %>_path<%= route[:params_str].empty? ? "" : "(#{route[:params_str]})" %>
7
+ <%= pending ? 'pending "now write some real specs. and remove pending mark."' + "\n " : "" %><%= route[:verb].downcase %> <%= route[:path_str] %>
8
8
  expect(response).to have_http_status(<%= route[:status] %>)
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Routes2spec
4
- VERSION = "0.2.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/routes2spec.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Generate Request specs and Routing specs of RSpec, from your Rails routes config. It is useful as a test scaffolding."
13
13
  spec.homepage = "https://github.com/shuuuuun/routes2spec"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.0"
15
+ spec.required_ruby_version = ">= 3.1.0"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/shuuuuun/routes2spec"
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency "rails", ">= 6.0"
33
+ spec.add_dependency "rails", "~> 6.1"
34
34
  # spec.add_dependency "rspec", ">= 3.9"
35
35
 
36
36
  # For more information and examples about making a new gem, check out our
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routes2spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shuuuuuny
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-01 00:00:00.000000000 Z
11
+ date: 2024-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '6.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: '6.1'
27
27
  description: Generate Request specs and Routing specs of RSpec, from your Rails routes
28
28
  config. It is useful as a test scaffolding.
29
29
  email: []
@@ -66,14 +66,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
- version: 2.7.0
69
+ version: 3.1.0
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubygems_version: 3.4.6
76
+ rubygems_version: 3.5.3
77
77
  signing_key:
78
78
  specification_version: 4
79
79
  summary: Generate Request specs and Routing specs of RSpec, from your Rails routes