routes2spec 0.1.0 → 0.3.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: fe60dcfbe04e4fb8eab34486d415fc35f96b4087d7cc3d526b2764b85e84c22b
4
- data.tar.gz: 91d6bbbb4e835fddf3ee82b66e2c58e0607cc75c468d013fb430ebb61f8027a7
3
+ metadata.gz: 79e4e2150811b3cc919d8db511042cc8a733e141f3c1d4e04891accbf364f922
4
+ data.tar.gz: '07904d17f0923955560f427586158be17578697bbf75e45eac0dae7728ccec63'
5
5
  SHA512:
6
- metadata.gz: 6a6ee2e33e390e4d70f70c50388e071381a56f96623ddfd47c1d0bb76749a9ce739ef048ad914bb65a96da3b05c7ac7a227f1b77e4363a5e85fda3c270db4960
7
- data.tar.gz: f306579044aba45f60890ab6093d5cf807bb0648f154dc3091b7b64c778e1a0f7c270c7319b3078da94f5163874e9fd8954c2c38faeb75487e95bd180029635f
6
+ metadata.gz: fe56ba68c66c4115fab4940447ac7641e439656f2ba7bd7819ba9f14324ef610a2be1df81efab02913bfe17854587718bc3557f4f47c0f081c5cf1a4f20864ac
7
+ data.tar.gz: c4887452c2fdc0c26216ff590be8b4fa8c24eb5844fb03ae10000ef67fec8807882918147286cbd8998516bf0f1500da45e862bdc4510fa3018696e4cef379d0
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
@@ -1,8 +1,13 @@
1
1
  # Routes2spec
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/routes2spec.svg)](https://badge.fury.io/rb/routes2spec)
4
+ [![Ruby](https://github.com/shuuuuun/routes2spec/actions/workflows/main.yml/badge.svg)](https://github.com/shuuuuun/routes2spec/actions/workflows/main.yml)
5
+
3
6
  Generate Request specs and Routing specs of RSpec, from your Rails routes config.
4
7
  It is useful as a test scaffolding.
5
8
 
9
+ **Currently does not work with Rails 7.**
10
+
6
11
  ## Installation
7
12
 
8
13
  Add this line to your application's Gemfile:
@@ -53,7 +58,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
53
58
 
54
59
  ## Contributing
55
60
 
56
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/routes2spec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/routes2spec/blob/main/CODE_OF_CONDUCT.md).
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shuuuuun/routes2spec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/shuuuuun/routes2spec/blob/main/CODE_OF_CONDUCT.md).
57
62
 
58
63
  ## License
59
64
 
@@ -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,9 +17,11 @@ 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 :overwrite, banner: "", desc: "Prompts for confirmation to overwrite each file if it already exists."
21
+ class_option :force_overwrite, banner: "", desc: "Forcibly overwrites existing files without confirmation."
20
22
  class_option :pending, banner: "", desc: "Mark examples as pending."
23
+ class_option :routing, type: :boolean, defalut: false, desc: "Generate routing specs."
24
+ class_option :verb, desc: "Generate only specific verb. Supported verbs: [#{SUPPORTED_VERBS.join(", ")}]"
21
25
 
22
26
  class << self
23
27
  def executable
@@ -36,6 +40,11 @@ module Routes2spec
36
40
  exit 0
37
41
  end
38
42
 
43
+ if options.verb? && !SUPPORTED_VERBS.include?(options.verb&.downcase)
44
+ say "Specified verb(#{options.verb}) is not supported! Supported verbs: [#{SUPPORTED_VERBS.join(", ")}]"
45
+ exit 1
46
+ end
47
+
39
48
  require_application_and_environment!
40
49
  require "action_dispatch/routing/inspector"
41
50
 
@@ -45,7 +54,7 @@ module Routes2spec
45
54
  writing_file(relative_path, result[:content])
46
55
 
47
56
  relative_path = File.join("spec/routing", *result[:namespaces], "#{result[:name].underscore}_spec.rb")
48
- writing_file(relative_path, result[:routing_content])
57
+ writing_file(relative_path, result[:routing_content]) if options.routing?
49
58
  end
50
59
  end
51
60
  # https://github.com/rails/rails/blob/v7.0.4/railties/lib/rails/command/base.rb#L144
@@ -106,7 +115,7 @@ module Routes2spec
106
115
  end
107
116
 
108
117
  def formatter_opts
109
- options.symbolize_keys.slice(:symbol_status, :pending)
118
+ options.symbolize_keys.slice(:symbol_status, :pending, :verb)
110
119
  end
111
120
  end
112
121
  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,15 +59,19 @@ 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Routes2spec
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/routes2spec.gemspec CHANGED
@@ -8,11 +8,11 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["shuuuuuny"]
9
9
  spec.email = []
10
10
 
11
- spec.summary = "routes2spec"
12
- spec.description = "routes2spec"
11
+ spec.summary = "Generate Request specs and Routing specs of RSpec, from your Rails routes config."
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,30 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routes2spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - shuuuuuny
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-06 00:00:00.000000000 Z
11
+ date: 2024-06-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'
27
- description: routes2spec
26
+ version: '6.1'
27
+ description: Generate Request specs and Routing specs of RSpec, from your Rails routes
28
+ config. It is useful as a test scaffolding.
28
29
  email: []
29
30
  executables:
30
31
  - routes2spec
@@ -65,15 +66,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
66
  requirements:
66
67
  - - ">="
67
68
  - !ruby/object:Gem::Version
68
- version: 2.7.0
69
+ version: 3.1.0
69
70
  required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  requirements:
71
72
  - - ">="
72
73
  - !ruby/object:Gem::Version
73
74
  version: '0'
74
75
  requirements: []
75
- rubygems_version: 3.3.26
76
+ rubygems_version: 3.5.3
76
77
  signing_key:
77
78
  specification_version: 4
78
- summary: routes2spec
79
+ summary: Generate Request specs and Routing specs of RSpec, from your Rails routes
80
+ config.
79
81
  test_files: []