r2m 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -1
- data/Gemfile +4 -4
- data/README.md +3 -5
- data/Rakefile +6 -6
- data/bin/console +3 -3
- data/lib/r2m/command.rb +29 -13
- data/lib/r2m/{processor.rb → spec_convector.rb} +9 -3
- data/lib/r2m/spec_migration.rb +33 -0
- data/lib/r2m/version.rb +1 -1
- data/lib/r2m.rb +1 -1
- data/sample_app/test/example_spec/example_test.rb +0 -0
- data/sample_app/test/example_test.rb +0 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ea8c25dfef6661109caeee0ca628389434080b154b1beeb1aad1c1515846f7
|
4
|
+
data.tar.gz: 4dd1416feddfc8b52e79dfcf4970cdcf3fb8d385885f7f261a8c5e2d0ca23e7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b470cdccf3d24ae191eb6b8b5d956a34f112c297a2be1f1e162ec240cdad5f225ec57df18b056905d8149bd4046f145b1570d563c04ad59a95974b829d0be4a1
|
7
|
+
data.tar.gz: f9dd5ca8be65e5ac323fb16f462ca0daa277a4ac059ca8a06cea3e394f22a25140e638d4036131b38dd5a1492c296969d929687293b8e3a315849bbf56a94f9c
|
data/.github/FUNDING.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in r2m.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem
|
7
|
-
gem
|
6
|
+
gem 'minitest', '~> 5.0'
|
7
|
+
gem 'rake', '~> 12.0'
|
8
8
|
|
9
|
-
gem 'rspec'
|
10
9
|
gem 'minitest-around'
|
11
10
|
gem 'minitest-spec-rails'
|
11
|
+
gem 'rspec'
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# RSpec To minitest
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
* Support Rails Matchers
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,7 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
$ r2m convert test/system/**/*_spec.rb
|
23
|
+
$ r2m convert "test/system/**/*_spec.rb"
|
26
24
|
|
27
25
|
## Development
|
28
26
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
8
|
end
|
9
9
|
|
10
|
-
task :
|
10
|
+
task default: :test
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'r2m'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "r2m"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/r2m/command.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'thor'
|
4
|
-
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
require_relative './spec_convector'
|
7
|
+
require_relative './spec_migration'
|
5
8
|
|
6
9
|
module R2M
|
7
10
|
# Adds CLI commands convert and migrate
|
@@ -15,30 +18,43 @@ module R2M
|
|
15
18
|
true
|
16
19
|
end
|
17
20
|
|
18
|
-
desc 'convert [
|
19
|
-
def convert(
|
20
|
-
files(
|
21
|
+
desc 'convert [path1 path2 ...]', 'Convert Rspec to minitest'
|
22
|
+
def convert(*paths)
|
23
|
+
files(paths.flatten).each { |path| run_convert path }
|
21
24
|
end
|
22
25
|
|
23
|
-
desc 'migrate [
|
24
|
-
method_option
|
26
|
+
desc 'migrate [path1 path2 ...]', 'Move found specs to test folder and convert them'
|
27
|
+
method_option(
|
28
|
+
:replace_suffix,
|
25
29
|
desc: 'Renames *_spec.rb to *_test.rb',
|
26
30
|
default: true,
|
27
31
|
aliases: ['s'],
|
28
32
|
type: :boolean
|
29
|
-
|
30
|
-
|
33
|
+
)
|
34
|
+
def migrate(*paths)
|
35
|
+
files(paths.flatten).each do |path|
|
36
|
+
say "Processing #{path}"
|
37
|
+
run_migrate(path)
|
38
|
+
run_convert(path)
|
39
|
+
end
|
31
40
|
end
|
32
41
|
|
33
42
|
private
|
34
43
|
|
35
|
-
def
|
36
|
-
|
44
|
+
def run_migrate(path)
|
45
|
+
SpecMigration.new(Pathname.pwd).migrate(File.realpath(path))
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_convert(file)
|
49
|
+
say "Processing #{file}"
|
50
|
+
SpecConvector.new(self).process(file)
|
37
51
|
end
|
38
52
|
|
39
|
-
def files(
|
40
|
-
Array(
|
41
|
-
if
|
53
|
+
def files(paths)
|
54
|
+
Array(paths).map do |path|
|
55
|
+
if File.exist?(path) && !File.directory?(path)
|
56
|
+
path
|
57
|
+
elsif Dir.exist?(path)
|
42
58
|
Dir.glob(File.join(path, '**', '*_spec.rb'))
|
43
59
|
else
|
44
60
|
Dir.glob(path)
|
@@ -4,7 +4,7 @@ require 'thor'
|
|
4
4
|
|
5
5
|
module R2M
|
6
6
|
# Process input RSpec and convert it to minitest
|
7
|
-
class
|
7
|
+
class SpecConvector # rubocop:todo Metrics/ClassLength
|
8
8
|
def initialize(command)
|
9
9
|
@command = command
|
10
10
|
end
|
@@ -76,18 +76,23 @@ module R2M
|
|
76
76
|
@command.gsub_file(file, /\bhelper\./, '') if located_in_helpers?(file)
|
77
77
|
end
|
78
78
|
|
79
|
-
|
79
|
+
# rubocop:todo Metrics/MethodLength
|
80
|
+
def convert_declarations(file) # rubocop:todo Metrics/AbcSize
|
80
81
|
@command.gsub_file(file, /RSpec\.describe (['"])(.*?)\1 do\b/) do |match|
|
81
82
|
title = match[/RSpec\.describe (['"])(.*?)\1 do/, 2]
|
82
83
|
|
84
|
+
# rubocop:todo Naming/VariableName
|
83
85
|
camelCasedTitle = title.split('::').map do |title_part|
|
84
86
|
title_part
|
85
87
|
.split
|
86
88
|
.reject(&:empty?)
|
87
89
|
.map { |part| part[0].upcase + part[1..-1] }.join
|
88
90
|
end.join('::')
|
91
|
+
# rubocop:enable Naming/VariableName
|
89
92
|
|
93
|
+
# rubocop:todo Naming/VariableName
|
90
94
|
"RSpec.describe '#{camelCasedTitle}' do"
|
95
|
+
# rubocop:enable Naming/VariableName
|
91
96
|
end
|
92
97
|
|
93
98
|
@command.gsub_file(
|
@@ -129,6 +134,7 @@ module R2M
|
|
129
134
|
'class \1Test < ActiveSupport::TestCase'
|
130
135
|
)
|
131
136
|
end
|
137
|
+
# rubocop:enable Metrics/MethodLength
|
132
138
|
|
133
139
|
MANUAL_AROUND_PROCESS = "skip 'TODO: Remove this skip when `around` will be migrated manually by replacing `run` with `call`'"
|
134
140
|
def convert_around(file)
|
@@ -148,7 +154,7 @@ module R2M
|
|
148
154
|
end
|
149
155
|
|
150
156
|
def located_in?(file, sub_folder)
|
151
|
-
file =~
|
157
|
+
file =~ %r{(test|spec)/#{sub_folder}/}
|
152
158
|
end
|
153
159
|
end
|
154
160
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rake/file_utils'
|
4
|
+
|
5
|
+
class SpecMigration # rubocop:todo Style/Documentation
|
6
|
+
def initialize(basedir)
|
7
|
+
@basedir = Pathname(basedir)
|
8
|
+
end
|
9
|
+
|
10
|
+
def migrate(spec_file) # rubocop:todo Metrics/AbcSize
|
11
|
+
move_and_rename_spec_to_test(spec_file)
|
12
|
+
end
|
13
|
+
|
14
|
+
def split_path(file)
|
15
|
+
spec_root = @basedir / 'spec'
|
16
|
+
dirname, basename = Pathname(file).split
|
17
|
+
relative_path = dirname.relative_path_from(spec_root)
|
18
|
+
|
19
|
+
[relative_path, basename]
|
20
|
+
end
|
21
|
+
|
22
|
+
def move_and_rename_spec_to_test(spec_file)
|
23
|
+
relative_path, spec_basename = split_path(spec_file)
|
24
|
+
test_root = @basedir / 'test'
|
25
|
+
|
26
|
+
test_dirname = test_root + relative_path
|
27
|
+
FileUtils.mkdir_p test_dirname
|
28
|
+
|
29
|
+
test_basename = spec_basename.sub(/_spec(?=\.rb)/, '_test')
|
30
|
+
test_file = test_dirname + test_basename
|
31
|
+
FileUtils.cp spec_file, test_file
|
32
|
+
end
|
33
|
+
end
|
data/lib/r2m/version.rb
CHANGED
data/lib/r2m.rb
CHANGED
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r2m
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Keen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -50,9 +50,12 @@ files:
|
|
50
50
|
- exe/rspec2minitest
|
51
51
|
- lib/r2m.rb
|
52
52
|
- lib/r2m/command.rb
|
53
|
-
- lib/r2m/
|
53
|
+
- lib/r2m/spec_convector.rb
|
54
|
+
- lib/r2m/spec_migration.rb
|
54
55
|
- lib/r2m/version.rb
|
55
56
|
- r2m.gemspec
|
57
|
+
- sample_app/test/example_spec/example_test.rb
|
58
|
+
- sample_app/test/example_test.rb
|
56
59
|
homepage: https://github.com/jetthoughts/r2m
|
57
60
|
licenses:
|
58
61
|
- MIT
|