minitest_to_rspec 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +6 -5
- data/bin/mt2rspec +3 -0
- data/lib/minitest_to_rspec/cli.rb +98 -0
- data/lib/minitest_to_rspec/exp/klass.rb +38 -2
- data/lib/minitest_to_rspec/subprocessors/klass.rb +27 -63
- data/lib/minitest_to_rspec/version.rb +1 -1
- data/minitest_to_rspec.gemspec +2 -1
- metadata +19 -4
- data/bin/minitest_to_rspec +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7af6cefcb0786c8e45326f8620a786ad8f2fe89
|
4
|
+
data.tar.gz: 67ca2d184a2ea2b98dda827c70e3a5fbaf44dfbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71242e74b6d2c4801191aa11e85214c8ab28b2390e265a9b043c22b64fa05a9ff2e238164c601081a6c89a347e1ae8b840e27541d495fc81f132527f6820c613
|
7
|
+
data.tar.gz: d86f72884d87dba2b95b07132ab0e1a20ce463a4723056ff16c4292c0df2330bbc55e3552e45523521fff6e1ff99aa219b15d9a6f224fe798b8fe49c425a8205
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,14 @@ Change Log
|
|
4
4
|
This project follows [semver 2.0.0][1] and the recommendations
|
5
5
|
of [keepachangelog.com][2].
|
6
6
|
|
7
|
+
0.5.0
|
8
|
+
-----
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- Executable
|
12
|
+
- Renamed from `minitest_to_rspec` to `mt2rspec`
|
13
|
+
- The `target_file` argument is now optional
|
14
|
+
|
7
15
|
0.4.0
|
8
16
|
-----
|
9
17
|
|
data/README.md
CHANGED
@@ -4,9 +4,9 @@ Converts [minitest][8] files to [rspec][9].
|
|
4
4
|
|
5
5
|
[![Build Status][1]][2] [![Code Climate][3]][4] [![Test Coverage][7]][4]
|
6
6
|
|
7
|
-
Selected assertions from [Test::Unit][26], [minitest][8],
|
8
|
-
[ActiveSupport][27] are converted to [rspec-expectations][25].
|
9
|
-
Selected methods from [mocha][28] are converted to [rspec-mocks][24].
|
7
|
+
- Selected assertions from [Test::Unit][26], [minitest][8],
|
8
|
+
and [ActiveSupport][27] are converted to [rspec-expectations][25].
|
9
|
+
- Selected methods from [mocha][28] are converted to [rspec-mocks][24].
|
10
10
|
|
11
11
|
Example
|
12
12
|
-------
|
@@ -46,8 +46,9 @@ Usage
|
|
46
46
|
### CLI
|
47
47
|
|
48
48
|
```bash
|
49
|
-
gem install
|
50
|
-
bundle exec
|
49
|
+
gem install mt2rspec
|
50
|
+
bundle exec mt2rspec [--rails] source_file [target_file]
|
51
|
+
bundle exec mt2rspec --help
|
51
52
|
```
|
52
53
|
|
53
54
|
### Ruby
|
data/bin/mt2rspec
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require "minitest_to_rspec"
|
2
|
+
require "trollop"
|
3
|
+
|
4
|
+
# https://github.com/ManageIQ/trollop/issues/57
|
5
|
+
module Trollop
|
6
|
+
def self.educate_without_exiting
|
7
|
+
@last_parser.educate($stderr)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module MinitestToRspec
|
12
|
+
class CLI
|
13
|
+
E_USAGE = 1.freeze
|
14
|
+
E_FILE_NOT_FOUND = 2.freeze
|
15
|
+
E_FILE_ALREADY_EXISTS = 3.freeze
|
16
|
+
E_CONVERT_FAIL = 4.freeze
|
17
|
+
|
18
|
+
BANNER = <<EOS.freeze
|
19
|
+
Usage: mt2rspec --rails source_file [target_file]
|
20
|
+
|
21
|
+
Reads source_file, writes target_file. If target_file is omitted,
|
22
|
+
its location will be inferred. For example, test/fruit/banana_test.rb
|
23
|
+
implies spec/fruit/banana_spec.rb.
|
24
|
+
|
25
|
+
Options:
|
26
|
+
EOS
|
27
|
+
|
28
|
+
OPT_RAILS = <<EOS.gsub(/\n/, " ").freeze
|
29
|
+
Requires rails_helper instead of spec_helper.
|
30
|
+
Passes :type metadatum to RSpec.describe.
|
31
|
+
EOS
|
32
|
+
|
33
|
+
attr_reader :rails, :source, :target
|
34
|
+
|
35
|
+
def initialize(args)
|
36
|
+
opts = Trollop::options(args) do
|
37
|
+
version MinitestToRspec::VERSION
|
38
|
+
banner BANNER
|
39
|
+
opt :rails, OPT_RAILS, short: :none
|
40
|
+
end
|
41
|
+
|
42
|
+
@rails = opts[:rails]
|
43
|
+
case args.length
|
44
|
+
when 2
|
45
|
+
@source, @target = args
|
46
|
+
when 1
|
47
|
+
@source = args[0]
|
48
|
+
@target = infer_target_from @source
|
49
|
+
else
|
50
|
+
Trollop.educate_without_exiting
|
51
|
+
exit(E_USAGE)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def run
|
56
|
+
assert_file_exists(source)
|
57
|
+
assert_file_does_not_exist(target)
|
58
|
+
write_target(converter.convert(read_source))
|
59
|
+
rescue Error => e
|
60
|
+
$stderr.puts "Failed to convert: #{e}"
|
61
|
+
exit E_CONVERT_FAIL
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def assert_file_exists(file)
|
67
|
+
unless File.exist?(file)
|
68
|
+
$stderr.puts "File not found: #{file}"
|
69
|
+
exit(E_FILE_NOT_FOUND)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def assert_file_does_not_exist(file)
|
74
|
+
if File.exist?(file)
|
75
|
+
$stderr.puts "File already exists: #{file}"
|
76
|
+
exit(E_FILE_ALREADY_EXISTS)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def converter
|
81
|
+
Converter.new(rails: rails)
|
82
|
+
end
|
83
|
+
|
84
|
+
def infer_target_from(source)
|
85
|
+
source.
|
86
|
+
gsub(/\Atest/, "spec").
|
87
|
+
gsub(/_test.rb\Z/, "_spec.rb")
|
88
|
+
end
|
89
|
+
|
90
|
+
def read_source
|
91
|
+
File.read(source)
|
92
|
+
end
|
93
|
+
|
94
|
+
def write_target(str)
|
95
|
+
File.write(target, str)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -11,6 +11,14 @@ module MinitestToRspec
|
|
11
11
|
assert_valid_name
|
12
12
|
end
|
13
13
|
|
14
|
+
def action_controller_test_case?
|
15
|
+
lineage?(parent, [:ActionController, :TestCase])
|
16
|
+
end
|
17
|
+
|
18
|
+
def active_support_test_case?
|
19
|
+
lineage?(parent, [:ActiveSupport, :TestCase])
|
20
|
+
end
|
21
|
+
|
14
22
|
# Raise an error if we don't know now to process the name
|
15
23
|
# of this class. Specifically, classes with module-shorthand.
|
16
24
|
def assert_valid_name
|
@@ -23,8 +31,12 @@ module MinitestToRspec
|
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|
34
|
+
def block?
|
35
|
+
!block.empty?
|
36
|
+
end
|
37
|
+
|
26
38
|
def block
|
27
|
-
@exp[3..-1] || []
|
39
|
+
@_block ||= @exp[3..-1] || []
|
28
40
|
end
|
29
41
|
|
30
42
|
# Returns the name of the class. Examples:
|
@@ -46,7 +58,31 @@ module MinitestToRspec
|
|
46
58
|
# - Inherit Bar::Foo #=> s(:colon2, s(:const, :Bar), :Foo)
|
47
59
|
#
|
48
60
|
def parent
|
49
|
-
@exp[2]
|
61
|
+
@_parent ||= @exp[2]
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns true if `@exp` inherits from, e.g. ActiveSupport::TestCase.
|
65
|
+
# TODO: Other test case parent classes.
|
66
|
+
def test_case?
|
67
|
+
return false unless sexp_type?(:colon2, parent)
|
68
|
+
active_support_test_case? ||
|
69
|
+
action_controller_test_case?
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def ancestor_name(exp, index)
|
75
|
+
assert_sexp_type(:colon2, exp)
|
76
|
+
ancestor = exp[index + 1]
|
77
|
+
sexp_type?(:const, ancestor) ? ancestor[1] : ancestor
|
78
|
+
end
|
79
|
+
|
80
|
+
def lineage?(exp, names)
|
81
|
+
assert_sexp_type(:colon2, exp)
|
82
|
+
exp.length == names.length + 1 &&
|
83
|
+
names.each_with_index.all? { |name, ix|
|
84
|
+
name.to_sym == ancestor_name(exp, ix).to_sym
|
85
|
+
}
|
50
86
|
end
|
51
87
|
end
|
52
88
|
end
|
@@ -16,37 +16,16 @@ module MinitestToRspec
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def process
|
19
|
-
|
20
|
-
block
|
21
|
-
|
22
|
-
result
|
19
|
+
sexp = head
|
20
|
+
sexp << block if @exp.block?
|
21
|
+
sexp
|
23
22
|
end
|
24
23
|
|
25
24
|
private
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
def active_support_test_case?(exp)
|
32
|
-
lineage?(exp, [:ActiveSupport, :TestCase])
|
33
|
-
end
|
34
|
-
|
35
|
-
def ancestor_name(exp, index)
|
36
|
-
assert_sexp_type(:colon2, exp)
|
37
|
-
ancestor = exp[index + 1]
|
38
|
-
sexp_type?(:const, ancestor) ? ancestor[1] : ancestor
|
39
|
-
end
|
40
|
-
|
41
|
-
# Returns the root of the result: either an :iter representing
|
42
|
-
# an `RSpec.describe` or, if it's not a test case, a :class.
|
43
|
-
def build_root(name, parent)
|
44
|
-
if parent && test_case?(parent)
|
45
|
-
md = rspec_describe_metadata(parent)
|
46
|
-
rspec_describe_block(name, md)
|
47
|
-
else
|
48
|
-
s(:class, name, parent)
|
49
|
-
end
|
26
|
+
# Returns a :block S-expression, the contents of the class.
|
27
|
+
def block
|
28
|
+
s(:block) + @exp.block.map { |line| full_process(line) }
|
50
29
|
end
|
51
30
|
|
52
31
|
# Given a `test_class_name` like `BananaTest`, returns the
|
@@ -55,34 +34,20 @@ module MinitestToRspec
|
|
55
34
|
test_class_name.to_s.gsub(/Test\Z/, "").to_sym
|
56
35
|
end
|
57
36
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
def rspec_describe(arg, metadata)
|
67
|
-
call = s(:call, s(:const, :RSpec), :describe, arg)
|
68
|
-
unless metadata.nil?
|
69
|
-
call << metadata
|
37
|
+
# Returns the head of the output Sexp. If it's a test case,
|
38
|
+
# an :iter representing an `RSpec.describe`. Otherwise, a :class.
|
39
|
+
def head
|
40
|
+
if @exp.test_case?
|
41
|
+
rspec_describe_block
|
42
|
+
else
|
43
|
+
s(:class, @exp.name, @exp.parent)
|
70
44
|
end
|
71
|
-
call
|
72
45
|
end
|
73
46
|
|
74
|
-
# Returns
|
75
|
-
|
76
|
-
|
77
|
-
s(:
|
78
|
-
end
|
79
|
-
|
80
|
-
def rspec_describe_metadata(exp)
|
81
|
-
if @rails
|
82
|
-
s(:hash, s(:lit, :type), s(:lit, rdm_type(exp)))
|
83
|
-
else
|
84
|
-
nil
|
85
|
-
end
|
47
|
+
# Returns an S-expression representing the
|
48
|
+
# RDM (RSpec Describe Metadata) hash
|
49
|
+
def rdm
|
50
|
+
s(:hash, s(:lit, :type), s(:lit, rdm_type))
|
86
51
|
end
|
87
52
|
|
88
53
|
# Returns the RDM (RSpec Describe Metadata) type.
|
@@ -98,25 +63,24 @@ module MinitestToRspec
|
|
98
63
|
# > http://bit.ly/1G5w7CJ
|
99
64
|
#
|
100
65
|
# TODO: Obviously, they're not all supported yet.
|
101
|
-
def rdm_type
|
102
|
-
if action_controller_test_case?
|
66
|
+
def rdm_type
|
67
|
+
if @exp.action_controller_test_case?
|
103
68
|
:controller
|
104
69
|
else
|
105
70
|
:model
|
106
71
|
end
|
107
72
|
end
|
108
73
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
74
|
+
def rspec_describe
|
75
|
+
const = s(:const, described_class(@exp.name))
|
76
|
+
call = s(:call, s(:const, :RSpec), :describe, const)
|
77
|
+
call << rdm if @rails
|
78
|
+
call
|
113
79
|
end
|
114
80
|
|
115
|
-
#
|
116
|
-
|
117
|
-
|
118
|
-
assert_sexp_type(:colon2, exp)
|
119
|
-
active_support_test_case?(exp) || action_controller_test_case?(exp)
|
81
|
+
# Returns a S-expression representing a call to RSpec.describe
|
82
|
+
def rspec_describe_block
|
83
|
+
s(:iter, rspec_describe, s(:args))
|
120
84
|
end
|
121
85
|
end
|
122
86
|
end
|
data/minitest_to_rspec.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'minitest_to_rspec/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "minitest_to_rspec"
|
8
8
|
spec.version = MinitestToRspec::VERSION
|
9
|
-
spec.executables << '
|
9
|
+
spec.executables << 'mt2rspec'
|
10
10
|
spec.authors = ["Jared Beck"]
|
11
11
|
spec.email = ["jared@jaredbeck.com"]
|
12
12
|
|
@@ -27,6 +27,7 @@ ruby2ruby.
|
|
27
27
|
|
28
28
|
spec.add_runtime_dependency "ruby_parser", "~> 3.6"
|
29
29
|
spec.add_runtime_dependency "ruby2ruby", "~> 2.1"
|
30
|
+
spec.add_runtime_dependency "trollop", "~> 2.1"
|
30
31
|
|
31
32
|
spec.add_development_dependency "bundler", "~> 1.7"
|
32
33
|
spec.add_development_dependency "cane", "~> 2.6"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest_to_rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Beck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_parser
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: trollop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,7 +157,7 @@ description: |
|
|
143
157
|
email:
|
144
158
|
- jared@jaredbeck.com
|
145
159
|
executables:
|
146
|
-
-
|
160
|
+
- mt2rspec
|
147
161
|
extensions: []
|
148
162
|
extra_rdoc_files: []
|
149
163
|
files:
|
@@ -157,12 +171,13 @@ files:
|
|
157
171
|
- README.md
|
158
172
|
- Rakefile
|
159
173
|
- bin/console
|
160
|
-
- bin/
|
174
|
+
- bin/mt2rspec
|
161
175
|
- doc/code_style.md
|
162
176
|
- doc/minitest.md
|
163
177
|
- doc/rspec.md
|
164
178
|
- doc/supported_assertions.md
|
165
179
|
- lib/minitest_to_rspec.rb
|
180
|
+
- lib/minitest_to_rspec/cli.rb
|
166
181
|
- lib/minitest_to_rspec/converter.rb
|
167
182
|
- lib/minitest_to_rspec/errors.rb
|
168
183
|
- lib/minitest_to_rspec/exp/base.rb
|
data/bin/minitest_to_rspec
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'minitest_to_rspec'
|
4
|
-
|
5
|
-
module MinitestToRspec
|
6
|
-
class CLI
|
7
|
-
E_USAGE = 1
|
8
|
-
E_FILE_NOT_FOUND = 2
|
9
|
-
E_FILE_ALREADY_EXISTS = 3
|
10
|
-
E_CONVERT_FAIL = 4
|
11
|
-
|
12
|
-
def initialize(args)
|
13
|
-
check_usage(args)
|
14
|
-
@target = args.pop
|
15
|
-
@source = args.pop
|
16
|
-
@rails = false
|
17
|
-
parse_options(args)
|
18
|
-
end
|
19
|
-
|
20
|
-
def run
|
21
|
-
assert_file_exists(@source)
|
22
|
-
assert_file_does_not_exist(@target)
|
23
|
-
write_target(converter.convert(read_source))
|
24
|
-
rescue Error => e
|
25
|
-
$stderr.puts "Failed to convert: #{e}"
|
26
|
-
exit E_CONVERT_FAIL
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def assert_file_exists(file)
|
32
|
-
unless File.exist?(file)
|
33
|
-
$stderr.puts "File not found: #{file}"
|
34
|
-
exit(E_FILE_NOT_FOUND)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def assert_file_does_not_exist(file)
|
39
|
-
if File.exist?(file)
|
40
|
-
$stderr.puts "File already exists: #{file}"
|
41
|
-
exit(E_FILE_ALREADY_EXISTS)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def check_usage(args)
|
46
|
-
unless (2..3).cover?(args.length)
|
47
|
-
print_usage
|
48
|
-
exit(E_USAGE)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def converter
|
53
|
-
Converter.new(rails: @rails)
|
54
|
-
end
|
55
|
-
|
56
|
-
def parse_options(args)
|
57
|
-
raise ArgumentError unless args.length <= 1
|
58
|
-
args.each do |arg|
|
59
|
-
case arg
|
60
|
-
when "--rails"
|
61
|
-
@rails = true
|
62
|
-
else
|
63
|
-
raise ArgumentError, "Unexpected option: #{arg}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def print_usage
|
69
|
-
$stderr.puts "Usage: minitest_to_rspec --rails source_file target_file"
|
70
|
-
end
|
71
|
-
|
72
|
-
def read_source
|
73
|
-
File.read(@source)
|
74
|
-
end
|
75
|
-
|
76
|
-
def write_target(str)
|
77
|
-
File.write(@target, str)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
MinitestToRspec::CLI.new(ARGV).run
|