r2m 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/exe/rspec2minitest +24 -10
- data/lib/r2m/processor.rb +115 -0
- data/lib/r2m/version.rb +1 -1
- data/r2m.gemspec +17 -15
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39cf102836307d757425f6c28d74674bb77001f61f7506ef1babf56b531f0405
|
4
|
+
data.tar.gz: a481c0b6dd240ea5f908d6481f8cdef1b61fa748bdf83d3c526890b0be9be894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26b7a0da0e111484d6fcd55954c9d8efbccfc223279a220abe81b0438225fc868335051e2d77e78542ad8126d75115712a67cf156c927ed9f9402e284c889c84
|
7
|
+
data.tar.gz: 3db7a67f1bbfef5c88e1a95e942b0b93e37230c9417334a78c56d3fdaacf063c234db93389b17b59feb28ac275c344bc788ca80c7989ee883f091903635e62fd
|
data/Gemfile
CHANGED
data/exe/rspec2minitest
CHANGED
@@ -6,14 +6,20 @@ cp -a $tests_path test/
|
|
6
6
|
|
7
7
|
tests_path=test/$(basename $tests_path)
|
8
8
|
|
9
|
+
# require helpers
|
9
10
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/system_helper/application_system_test_case/g' {} \;
|
10
11
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/rails_helper/test_helper/g' {} \;
|
11
12
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/spec_helper/test_helper/g' {} \;
|
13
|
+
|
12
14
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/context/describe/g' {} \;
|
15
|
+
|
16
|
+
# mocks
|
13
17
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/stub(/stubs(/g' {} \;
|
14
18
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/double/stub/g' {} \;
|
15
19
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/should_receive/expects/g' {} \;
|
16
20
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/and_return/returns/g' {} \;
|
21
|
+
|
22
|
+
# matchers
|
17
23
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to be ==/.must_equal/g' {} \;
|
18
24
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to be_empty/.must_be_empty/g' {} \;
|
19
25
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to_not be_empty/.wont_be_empty/g' {} \;
|
@@ -24,21 +30,29 @@ find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to_not be_nil/.wont_be_ni
|
|
24
30
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.not_to be_an_\(.*\)/.wont_be :\1\?/g' {} \;
|
25
31
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to be_a(/.must_be_kind_of(/g' {} \;
|
26
32
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to be_an(/.must_be_kind_of(/g' {} \;
|
33
|
+
|
27
34
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to be_an_\(.*\)/.must_be :\1\?/g' {} \;
|
35
|
+
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to be_\(.*\)/.must_be :\1\?/g' {} \;
|
28
36
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to_not be_\(.*\)/.wont_be :\1\?/g' {} \;
|
29
37
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.not_to be_\(.*\)/.wont_be :\1\?/g' {} \;
|
30
|
-
|
38
|
+
|
31
39
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to be_nil/.must_be_nil/g' {} \;
|
40
|
+
|
32
41
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to eq/.must_equal/g' {} \;
|
33
42
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.not_to eq/.wont_equal/g' {} \;
|
34
43
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to_not eq/.wont_equal/g' {} \;
|
44
|
+
|
35
45
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.not_to include/.wont_include/g' {} \;
|
36
46
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to_not include/.wont_include/g' {} \;
|
37
47
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to include/.must_include/g' {} \;
|
48
|
+
|
49
|
+
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to match/.must_match/g' {} \;
|
50
|
+
|
38
51
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/\.to be_kind_of/.must_be_kind_of/g' {} \;
|
52
|
+
|
53
|
+
# requests
|
39
54
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/expect(response).to have_http_status/assert_response/g' {} \;
|
40
55
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to redirect_to/.must_redirect_to/g' {} \;
|
41
|
-
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to match/.must_match/g' {} \;
|
42
56
|
|
43
57
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to have_content/assert_text/g' {} \;
|
44
58
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to have_no_content/assert_no_text/g' {} \;
|
@@ -46,19 +60,18 @@ find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(
|
|
46
60
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to have_selector/assert_selector/g' {} \;
|
47
61
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.not_to have_selector/assert_no_selector/g' {} \;
|
48
62
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to_not have_selector/assert_no_selector/g' {} \;
|
63
|
+
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to have_checked_field/assert_checked_field/g' {} \;
|
64
|
+
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.not_to have_checked_field/assert_no_checked_field/g' {} \;
|
65
|
+
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to_not have_checked_field/assert_no_checked_field/g' {} \;
|
49
66
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.to have_content/.must_have_content/g' {} \;
|
50
67
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.not_to have_content/.wont_have_content/g' {} \;
|
51
68
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.to have_no_content/.wont_have_content/g' {} \;
|
52
69
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.to have_field/.must_have_field/g' {} \;
|
53
|
-
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to have_checked_field/assert_checked_field/g' {} \;
|
54
|
-
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.not_to have_checked_field/assert_no_checked_field/g' {} \;
|
55
|
-
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/expect(page)\.to_not have_checked_field/assert_no_checked_field/g' {} \;
|
56
70
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.to have_link/.must_have_link/g' {} \;
|
57
71
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.to have_no_link/.wont_have_link/g' {} \;
|
58
72
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.to have_button/.must_have_button/g' {} \;
|
59
73
|
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/\.to have_no_button/.wont_have_button/g' {} \;
|
60
74
|
|
61
|
-
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/.to match/.must_match/g' {} \;
|
62
75
|
|
63
76
|
find $tests_path -name '*_spec.rb' -exec sed -i '' "s/expect[ {]/skip('FIXME: NEED TO MIGRATE MANUALLY FROM RSPEC')
|
64
77
|
expect /g" {} \;
|
@@ -66,21 +79,22 @@ expect /g" {} \;
|
|
66
79
|
|
67
80
|
find $tests_path -path '*/helpers/*' -name '*_spec.rb' -exec sed -i '' 's/helper\.//g' {} \;
|
68
81
|
|
69
|
-
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe '"'"'\(.*\)'"'"' do.*/Class.new(ApplicationSystemTestCase) do #\1/g' {} \;
|
70
|
-
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/, screenshot: true//g' {} \;
|
71
|
-
|
72
82
|
find $tests_path -path '*/controllers/*' -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe \(.*Controller\).*/class \1Test < ActionController::TestCase/g' {} \;
|
73
83
|
find $tests_path -path '*/mailers/*' -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe \(.*Mailer\).*/class \1Test < ActionMailer::TestCase/g' {} \;
|
74
84
|
find $tests_path -path '*/helpers/*' -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe \(.*Helper\).*/class \1Test < ActionView::TestCase/g' {} \;
|
75
|
-
|
76
85
|
find $tests_path -path '*/requests/*' -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe '"'"'\(.*\)'"'"' do.*/class \1Test < ActionDispatch::IntegrationTest/g' {} \;
|
77
86
|
|
87
|
+
find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe '"'"'\(.*\)'"'"' do.*/Class.new(ApplicationSystemTestCase) do #\1/g' {} \;
|
88
|
+
|
78
89
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe '"'"'\(.*\)'"'"' do/class \1Test < ActiveSupport::TestCase/g' {} \;
|
79
90
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/RSpec\.describe \(.*\) do/class \1Test < ActiveSupport::TestCase/g' {} \;
|
80
91
|
|
81
92
|
|
82
93
|
find $tests_path -name '*_spec.rb' -exec sed -i '' 's/around do/warn "FIX: AROUND"; around do/g' {} \;
|
83
94
|
|
95
|
+
# other project specific
|
96
|
+
#find $tests_path -path '*/system/*' -name '*_spec.rb' -exec sed -i '' 's/, screenshot: true//g' {} \;
|
97
|
+
|
84
98
|
|
85
99
|
rubocop --safe-auto-correct --disable-uncorrectable $tests_path
|
86
100
|
|
data/lib/r2m/processor.rb
CHANGED
@@ -11,7 +11,14 @@ module R2M
|
|
11
11
|
|
12
12
|
def process(file)
|
13
13
|
# it 'converts it"s to test method with # support' do # => def test_converts_it_s_to_test_method_with_support
|
14
|
+
convert_require_helpers(file)
|
15
|
+
convert_declarations(file)
|
16
|
+
convert_declarations(file)
|
17
|
+
convert_context_to_describe(file)
|
14
18
|
convert_it_to_methods(file)
|
19
|
+
convert_helpers_suites(file)
|
20
|
+
convert_mather_be_empty(file)
|
21
|
+
convert_simple_matcher(file)
|
15
22
|
end
|
16
23
|
|
17
24
|
# Finds +it+ cases and converts to test methods declarations
|
@@ -26,6 +33,22 @@ module R2M
|
|
26
33
|
@command.gsub_file(file, /it '_?(.*)' do/, 'def test_\1')
|
27
34
|
end
|
28
35
|
|
36
|
+
# Finds +it+ cases and converts to test methods declarations
|
37
|
+
#
|
38
|
+
# context 'with context' do # => describe 'with context' do
|
39
|
+
def convert_context_to_describe(file)
|
40
|
+
@command.gsub_file(file, /\bcontext( '.*?' do\b)/, 'describe\1')
|
41
|
+
end
|
42
|
+
|
43
|
+
# Finds +it+ cases and converts to test methods declarations
|
44
|
+
#
|
45
|
+
# context 'with context' do # => describe 'with context' do
|
46
|
+
def convert_require_helpers(file)
|
47
|
+
@command.gsub_file(file, /\bsystem_helper\b/, 'application_system_test_case')
|
48
|
+
@command.gsub_file(file, /\b(rails_helper|spec_helper)\b/, 'test_helper')
|
49
|
+
@command.gsub_file(file, /require (['"]?)rspec\1/, "require 'minitest/autorun'")
|
50
|
+
end
|
51
|
+
|
29
52
|
# Finds +be_empty+ RSpec matchers and converts to minitest matchers
|
30
53
|
#
|
31
54
|
# expect(target).to be_empty # => expect(target).must_be_empty
|
@@ -35,5 +58,97 @@ module R2M
|
|
35
58
|
@command.gsub_file(file, /\.to be_empty/, '.must_be_empty')
|
36
59
|
@command.gsub_file(file, /\.(to_not|not_to) be_empty/, '.wont_be_empty')
|
37
60
|
end
|
61
|
+
|
62
|
+
# Finds +equal+ RSpec matchers and converts to minitest matchers
|
63
|
+
#
|
64
|
+
# expect(target).to eq expect # => expect(target).must_equal expect
|
65
|
+
# expect(target).not_to eq expect # => expect(target).wont_equal expect
|
66
|
+
def convert_simple_matcher(file)
|
67
|
+
@command.gsub_file(file, /\.(to_not|not_to|to)\s+(eq|include|match|be_kind_of)\b/) do |match|
|
68
|
+
match
|
69
|
+
.gsub(/\s+/, ' ')
|
70
|
+
.gsub(/\.\w+ /, '.to_not ' => '.wont_', '.not_to ' => '.wont_', '.to ' => '.must_')
|
71
|
+
.gsub(/(?<=_)eq/, 'equal')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def convert_helpers_suites(file)
|
76
|
+
@command.gsub_file(file, /\bhelper\./, '') if located_in_helpers?(file)
|
77
|
+
end
|
78
|
+
|
79
|
+
def convert_declarations(file)
|
80
|
+
@command.gsub_file(file, /RSpec\.describe (['"])(.*?)\1 do\b/) do |match|
|
81
|
+
title = match[/RSpec\.describe (['"])(.*?)\1 do/, 2]
|
82
|
+
|
83
|
+
camelCasedTitle = title.split('::').map do |title_part|
|
84
|
+
title_part
|
85
|
+
.split
|
86
|
+
.reject(&:empty?)
|
87
|
+
.map { |part| part[0].upcase + part[1..-1] }.join
|
88
|
+
end.join('::')
|
89
|
+
|
90
|
+
"RSpec.describe '#{camelCasedTitle}' do"
|
91
|
+
end
|
92
|
+
|
93
|
+
@command.gsub_file(
|
94
|
+
file,
|
95
|
+
/RSpec\.describe ['"]?(.+?Controller)['"]? do\b/,
|
96
|
+
'class \1Test < ActionController::TestCase'
|
97
|
+
)
|
98
|
+
@command.gsub_file(
|
99
|
+
file,
|
100
|
+
/RSpec\.describe ['"]?(.+?Mailer)['"]? do\b/,
|
101
|
+
'class \1Test < ActionMailer::TestCase'
|
102
|
+
)
|
103
|
+
|
104
|
+
@command.gsub_file(
|
105
|
+
file,
|
106
|
+
/RSpec\.describe ['"]?(.+?Helper)['"]? do\b/,
|
107
|
+
'class \1Test < ActionView::TestCase'
|
108
|
+
)
|
109
|
+
|
110
|
+
if located_in_requests?(file)
|
111
|
+
@command.gsub_file(
|
112
|
+
file,
|
113
|
+
/RSpec\.describe ['"]?(.+?)['"]? do\b/,
|
114
|
+
'class \1Test < ActionDispatch::IntegrationTest'
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
if located_in?(file, :systems)
|
119
|
+
@command.gsub_file(
|
120
|
+
file,
|
121
|
+
/RSpec\.describe ['"]?(.+?)['"]? do\b/,
|
122
|
+
'class \1Test < ApplicationSystemTestCase'
|
123
|
+
)
|
124
|
+
end
|
125
|
+
|
126
|
+
@command.gsub_file(
|
127
|
+
file,
|
128
|
+
/RSpec\.describe ['"]?(.+?)['"]? do\b/,
|
129
|
+
'class \1Test < ActiveSupport::TestCase'
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
MANUAL_AROUND_PROCESS = "skip 'TODO: Remove this skip when `around` will be migrated manually by replacing `run` with `call`'"
|
134
|
+
def convert_around(file)
|
135
|
+
@command.gsub_file(file, /^\s*?\baround\b.+?\bdo\b.*?$/) do |match|
|
136
|
+
"#{MANUAL_AROUND_PROCESS}\n#{match}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def located_in_helpers?(file)
|
143
|
+
located_in?(file, :helpers)
|
144
|
+
end
|
145
|
+
|
146
|
+
def located_in_requests?(file)
|
147
|
+
located_in?(file, :requests)
|
148
|
+
end
|
149
|
+
|
150
|
+
def located_in?(file, sub_folder)
|
151
|
+
file =~ /(test|spec)\/#{sub_folder}\//
|
152
|
+
end
|
38
153
|
end
|
39
154
|
end
|
data/lib/r2m/version.rb
CHANGED
data/r2m.gemspec
CHANGED
@@ -1,31 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/r2m/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
6
|
+
spec.name = 'r2m'
|
5
7
|
spec.version = R2M::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
+
spec.authors = ['Paul Keen']
|
9
|
+
spec.email = ['info@jetthoughts.com']
|
8
10
|
|
9
|
-
spec.summary =
|
10
|
-
spec.description =
|
11
|
-
spec.homepage =
|
12
|
-
spec.license =
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = 'Converts RSpec files to minitest'
|
12
|
+
spec.description = 'A command-line tool for converting RSpec files to minitest.'
|
13
|
+
spec.homepage = 'https://github.com/jetthoughts/r2m'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
14
16
|
|
15
17
|
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
18
|
|
17
|
-
spec.metadata[
|
18
|
-
spec.metadata[
|
19
|
-
spec.metadata[
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/jetthoughts/r2m'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/jetthoughts/r2m/README.md'
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test)/}) }
|
25
27
|
end
|
26
|
-
spec.bindir =
|
28
|
+
spec.bindir = 'exe'
|
27
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = [
|
30
|
+
spec.require_paths = ['lib']
|
29
31
|
|
30
|
-
spec.
|
32
|
+
spec.add_dependency 'thor'
|
31
33
|
end
|
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.3
|
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-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -17,7 +17,7 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|