rails5-spec-converter 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb40ce4087decb84d90621dbff3754da8bc1041d
4
+ data.tar.gz: 65f8db8ed9d02fd5620e0ab3b9ccc038c145f5b8
5
+ SHA512:
6
+ metadata.gz: c1c235aa76ee06967885c10c64317147c32cb7b45cf5efb55aee13bb8060e46d1b866a09bea38e2926ca4c0a50b4bc6a232036f96c1fed77c6c04f0de39b3cde
7
+ data.tar.gz: 34741b22342fa50139323f00b8ed12d801f3f90877c0a823e57082d96eb16f30cc36c7834995424057439f074bbc4459579d79fcde3446551316ceb4d86f6368
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .idea
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails5-spec-converter.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Travis Grathwell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # Rails5::SpecConverter
2
+
3
+ A script that fixes the syntax of your tests so Rails 5 will like them better. Inspired by [transpec](https://github.com/yujinakayama/transpec), the RSpec 2 -> 3 syntax conversion tool.
4
+
5
+ If you write a test like this:
6
+
7
+ ```
8
+ get :users, search: 'bayleef', format: :json
9
+ expect(response).to be_success
10
+ ```
11
+
12
+ Rails 5 will issue a hearty deprecation warning, persuading you to write this instead:
13
+
14
+ ```
15
+ get :users, params: { search: 'bayleef' }, format: :json
16
+ expect(response).to be_success
17
+ ```
18
+
19
+ This is great! That syntax is great. However, if you have a thousand tests lying around, it will probably be very time consuming to find all the places where you need to fix that.
20
+
21
+ ## Installation
22
+
23
+ Install the gem standalone like so:
24
+
25
+ $ gem install rails5-spec-converter
26
+
27
+ ## Usage
28
+
29
+ Make sure you've committed everything to Git first, then
30
+
31
+ $ cd some-project
32
+ $ rails5-spec-converter
33
+
34
+ This will update all the files in that directory matching the glob `spec/**/*_spec.rb`. It should be idempotent.
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tjgrathwell/rails5-spec-converter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
48
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec_converter)
5
+
6
+ task :default => :spec_converter
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails5/spec_converter"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))
4
+ require 'rails5/spec_converter/cli'
5
+
6
+ result = Rails5::SpecConverter::CLI.new.run
7
+ exit(result ? 0 : 1)
@@ -0,0 +1,2 @@
1
+ require "rails5/spec_converter/version"
2
+ require "rails5/spec_converter/text_transformer"
@@ -0,0 +1,15 @@
1
+ require 'rails5/spec_converter/text_transformer'
2
+
3
+ module Rails5
4
+ module SpecConverter
5
+ class CLI
6
+ def run
7
+ Dir.glob("spec/**/*_spec.rb") do |path|
8
+ original_content = File.read(path)
9
+ transformed_content = Rails5::SpecConverter::TextTransformer.new(original_content).transform
10
+ File.write(path, transformed_content)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,70 @@
1
+ require 'parser/current'
2
+ require 'astrolabe/builder'
3
+
4
+ module Rails5
5
+ module SpecConverter
6
+ HTTP_VERBS = %i(get post put patch delete)
7
+ # technically format is special
8
+ ALLOWED_KWARG_KEYS = %i(params session flash method body xhr format)
9
+
10
+ class TextTransformer
11
+ def initialize(content)
12
+ @content = content
13
+ end
14
+
15
+ def transform
16
+ source_buffer = Parser::Source::Buffer.new('(string)')
17
+ source_buffer.source = @content
18
+
19
+ ast_builder = Astrolabe::Builder.new
20
+ parser = Parser::CurrentRuby.new(ast_builder)
21
+
22
+ source_rewriter = Parser::Source::Rewriter.new(source_buffer)
23
+
24
+ root_node = parser.parse(source_buffer)
25
+ root_node.each_node(:send) do |node|
26
+ target, verb, action, first_argument = node.children
27
+ if target.nil? && HTTP_VERBS.include?(verb)
28
+ if first_argument && first_argument.hash_type?
29
+ hash_node = first_argument
30
+
31
+ pairs_that_belong_in_params = []
32
+ pairs_that_belong_outside_params = []
33
+
34
+ hash_node.children.each do |pair|
35
+ key = pair.children[0].children[0]
36
+
37
+ if ALLOWED_KWARG_KEYS.include?(key)
38
+ pairs_that_belong_outside_params << pair
39
+ else
40
+ pairs_that_belong_in_params << pair
41
+ end
42
+ end
43
+
44
+ curly_sep = hash_node.parent.loc.expression.source.match(/{\S/) ? '' : ' '
45
+
46
+ if pairs_that_belong_in_params.length > 0
47
+ rewritten_hashes = ["params: {#{curly_sep}#{restring_hash(pairs_that_belong_in_params)}#{curly_sep}}"]
48
+ if pairs_that_belong_outside_params.length > 0
49
+ rewritten_hashes << restring_hash(pairs_that_belong_outside_params)
50
+ end
51
+ source_rewriter.replace(
52
+ hash_node.loc.expression,
53
+ rewritten_hashes.join(', ')
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ source_rewriter.process
61
+ end
62
+
63
+ private
64
+
65
+ def restring_hash(pairs)
66
+ pairs.map { |pair| pair.loc.expression.source }.join(", ")
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module Rails5
2
+ module SpecConverter
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails5/spec_converter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails5-spec-converter"
8
+ spec.version = Rails5::SpecConverter::VERSION
9
+ spec.authors = ["Travis Grathwell"]
10
+ spec.email = ["tjgrathwell@gmail.com"]
11
+
12
+ spec.summary = %q{A tool to upgrade Rails 4-style specs to Rails 5-style}
13
+ spec.description = %q{Rails 5 issues a deprecation warning if your controller/request tests don't wrap user-supplied params in a `params` keyword. This helps with that.}
14
+ spec.homepage = "https://github.com/tjgrathwell/rails5-spec-converter"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency 'parser', '>= 2.3.0.7'
23
+ spec.add_runtime_dependency 'astrolabe', '~> 1.2'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "byebug"
29
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails5-spec-converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Travis Grathwell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.0.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.0.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: astrolabe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Rails 5 issues a deprecation warning if your controller/request tests
98
+ don't wrap user-supplied params in a `params` keyword. This helps with that.
99
+ email:
100
+ - tjgrathwell@gmail.com
101
+ executables:
102
+ - rails5-spec-converter
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - exe/rails5-spec-converter
117
+ - lib/rails5/spec_converter.rb
118
+ - lib/rails5/spec_converter/cli.rb
119
+ - lib/rails5/spec_converter/text_transformer.rb
120
+ - lib/rails5/spec_converter/version.rb
121
+ - rails5-spec-converter.gemspec
122
+ homepage: https://github.com/tjgrathwell/rails5-spec-converter
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: A tool to upgrade Rails 4-style specs to Rails 5-style
146
+ test_files: []