minitest_to_rspec 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +3 -2
- data/CHANGELOG.md +19 -0
- data/README.md +3 -0
- data/lib/minitest_to_rspec/converter.rb +2 -2
- data/lib/minitest_to_rspec/input/model/base.rb +15 -0
- data/lib/minitest_to_rspec/input/model/call.rb +185 -0
- data/lib/minitest_to_rspec/input/model/defn.rb +37 -0
- data/lib/minitest_to_rspec/input/model/hash_exp.rb +24 -0
- data/lib/minitest_to_rspec/input/model/iter.rb +89 -0
- data/lib/minitest_to_rspec/input/model/klass.rb +102 -0
- data/lib/minitest_to_rspec/input/processor.rb +40 -0
- data/lib/minitest_to_rspec/input/subprocessors/base.rb +91 -0
- data/lib/minitest_to_rspec/input/subprocessors/call.rb +279 -0
- data/lib/minitest_to_rspec/input/subprocessors/defn.rb +64 -0
- data/lib/minitest_to_rspec/input/subprocessors/iter.rb +148 -0
- data/lib/minitest_to_rspec/input/subprocessors/klass.rb +101 -0
- data/lib/minitest_to_rspec/minitest/stub.rb +85 -0
- data/lib/minitest_to_rspec/{expression_builders → rspec}/stub.rb +3 -2
- data/lib/minitest_to_rspec/type.rb +1 -1
- data/lib/minitest_to_rspec/version.rb +1 -1
- metadata +17 -18
- data/lib/minitest_to_rspec/model/base.rb +0 -13
- data/lib/minitest_to_rspec/model/call.rb +0 -165
- data/lib/minitest_to_rspec/model/calls/once.rb +0 -13
- data/lib/minitest_to_rspec/model/calls/twice.rb +0 -13
- data/lib/minitest_to_rspec/model/defn.rb +0 -27
- data/lib/minitest_to_rspec/model/hash_exp.rb +0 -20
- data/lib/minitest_to_rspec/model/iter.rb +0 -79
- data/lib/minitest_to_rspec/model/klass.rb +0 -100
- data/lib/minitest_to_rspec/processor.rb +0 -38
- data/lib/minitest_to_rspec/subprocessors/base.rb +0 -89
- data/lib/minitest_to_rspec/subprocessors/call.rb +0 -391
- data/lib/minitest_to_rspec/subprocessors/defn.rb +0 -49
- data/lib/minitest_to_rspec/subprocessors/iter.rb +0 -138
- data/lib/minitest_to_rspec/subprocessors/klass.rb +0 -99
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../model/defn'
|
4
|
-
require_relative 'base'
|
5
|
-
|
6
|
-
module MinitestToRspec
|
7
|
-
module Subprocessors
|
8
|
-
# Minitest tests can be defined as methods using names beginning with
|
9
|
-
# 'test_'. Process those tests into RSpec `it` example blocks.
|
10
|
-
class Defn < Base
|
11
|
-
def initialize(sexp, rails, mocha)
|
12
|
-
super(rails, mocha)
|
13
|
-
@original = sexp.dup
|
14
|
-
@exp = Model::Defn.new(sexp)
|
15
|
-
sexp.clear
|
16
|
-
end
|
17
|
-
|
18
|
-
# Using a `Model::Defn`, returns a `Sexp`
|
19
|
-
def process
|
20
|
-
if @exp.test_method?
|
21
|
-
s(:iter,
|
22
|
-
s(:call, nil, :it, s(:str, example_title)),
|
23
|
-
0,
|
24
|
-
example_block)
|
25
|
-
else
|
26
|
-
@original
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
# Remove 'test_' prefix and replace underscores with spaces
|
33
|
-
def example_title
|
34
|
-
@exp.method_name.sub(/^test_/, '').tr('_', ' ')
|
35
|
-
end
|
36
|
-
|
37
|
-
def example_block
|
38
|
-
block = s(:block)
|
39
|
-
@exp.body.each_with_object(block) do |line, blk|
|
40
|
-
blk << process_line(line)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def process_line(line)
|
45
|
-
::MinitestToRspec::Processor.new(@rails, @mocha).process(line)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'base'
|
4
|
-
require_relative '../model/iter'
|
5
|
-
|
6
|
-
module MinitestToRspec
|
7
|
-
module Subprocessors
|
8
|
-
# Processes `s(:iter, ..)` expressions.
|
9
|
-
class Iter < Base
|
10
|
-
def initialize(sexp, rails, mocha)
|
11
|
-
super(rails, mocha)
|
12
|
-
@exp = Model::Iter.new(sexp)
|
13
|
-
sexp.clear
|
14
|
-
end
|
15
|
-
|
16
|
-
def process
|
17
|
-
process_exp(@exp)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
# Returns an expression representing an RSpec `change {}`
|
23
|
-
# matcher. See also `change_by` below.
|
24
|
-
def change(exp)
|
25
|
-
matcher_with_block(:change, exp)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns an expression representing an RSpec `change {}.by()` matcher.
|
29
|
-
def change_by(diff_exp, by_exp)
|
30
|
-
s(:call,
|
31
|
-
change(diff_exp),
|
32
|
-
:by,
|
33
|
-
by_exp
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
def matcher_with_block(matcher_name, block)
|
38
|
-
s(:iter,
|
39
|
-
s(:call, nil, matcher_name),
|
40
|
-
0,
|
41
|
-
block
|
42
|
-
)
|
43
|
-
end
|
44
|
-
|
45
|
-
def method_assert_difference(exp)
|
46
|
-
call = exp[1]
|
47
|
-
block = exp[3]
|
48
|
-
by = call[4]
|
49
|
-
what = parse(call[3][1])
|
50
|
-
matcher = by.nil? ? change(what) : change_by(what, by)
|
51
|
-
expect_to(matcher, block, false)
|
52
|
-
end
|
53
|
-
|
54
|
-
def method_assert_no_difference(exp)
|
55
|
-
call = exp[1]
|
56
|
-
block = exp[3]
|
57
|
-
what = parse(call[3][1])
|
58
|
-
expect_to_not(change(what), block, false)
|
59
|
-
end
|
60
|
-
|
61
|
-
def method_assert_nothing_raised(exp)
|
62
|
-
block = exp[3]
|
63
|
-
expect_to_not(raise_error, block, false)
|
64
|
-
end
|
65
|
-
|
66
|
-
def method_assert_raise(iter)
|
67
|
-
method_assert_raises(iter)
|
68
|
-
end
|
69
|
-
|
70
|
-
def method_assert_raises(iter)
|
71
|
-
expect_to(raise_error(*iter.call_arguments), iter.block, false)
|
72
|
-
end
|
73
|
-
|
74
|
-
def method_setup(exp)
|
75
|
-
replace_method_name(exp, :before)
|
76
|
-
end
|
77
|
-
|
78
|
-
def method_teardown(exp)
|
79
|
-
replace_method_name(exp, :after)
|
80
|
-
end
|
81
|
-
|
82
|
-
def name_of_processing_method(iter)
|
83
|
-
method_name = iter[1][2]
|
84
|
-
"method_#{method_name}".to_sym
|
85
|
-
end
|
86
|
-
|
87
|
-
def parse(str)
|
88
|
-
RubyParser.new.parse(str)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Given a `Model::Iter`, returns a `Sexp`
|
92
|
-
def process_exp(exp)
|
93
|
-
if processable?(exp)
|
94
|
-
send_to_processing_method(exp)
|
95
|
-
else
|
96
|
-
process_uninteresting_iter(exp.sexp)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def processable?(iter)
|
101
|
-
if !iter.empty? && iter[1].sexp_type == :call
|
102
|
-
method_name = iter[1][2]
|
103
|
-
decision = "#{method_name}?".to_sym
|
104
|
-
iter.respond_to?(decision) && iter.public_send(decision)
|
105
|
-
else
|
106
|
-
false
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def process_uninteresting_iter(exp)
|
111
|
-
iter = s(exp.shift)
|
112
|
-
until exp.empty?
|
113
|
-
iter << full_process(exp.shift)
|
114
|
-
end
|
115
|
-
iter
|
116
|
-
end
|
117
|
-
|
118
|
-
# Given `args` which came from an `assert_raise` or an
|
119
|
-
# `assert_raises`, return a `raise_error` matcher.
|
120
|
-
# When the last argument is a string, it represents the
|
121
|
-
# assertion failure message, and is discarded.
|
122
|
-
def raise_error(*args)
|
123
|
-
args.pop if !args.empty? && args.last.sexp_type == :str
|
124
|
-
matcher(:raise_error, *args)
|
125
|
-
end
|
126
|
-
|
127
|
-
def replace_method_name(exp, new_method)
|
128
|
-
iter = s(:iter, s(:call, nil, new_method))
|
129
|
-
exp.each do |e| iter << full_process(e) end
|
130
|
-
iter
|
131
|
-
end
|
132
|
-
|
133
|
-
def send_to_processing_method(exp)
|
134
|
-
send(name_of_processing_method(exp), exp)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../errors'
|
4
|
-
require_relative '../model/klass'
|
5
|
-
require_relative 'base'
|
6
|
-
|
7
|
-
module MinitestToRspec
|
8
|
-
module Subprocessors
|
9
|
-
# Processes `s(:class, ..)` expressions.
|
10
|
-
class Klass < Base
|
11
|
-
# Takes `sexp`, a `:class` s-expression, and `rails`, a
|
12
|
-
# boolean indicating that `rspec-rails` conventions (like
|
13
|
-
# `:type` metadata) should be used.
|
14
|
-
def initialize(sexp, rails, mocha)
|
15
|
-
super(rails, mocha)
|
16
|
-
@exp = Model::Klass.new(sexp)
|
17
|
-
sexp.clear
|
18
|
-
end
|
19
|
-
|
20
|
-
def process
|
21
|
-
sexp = head
|
22
|
-
ebk = @exp.block
|
23
|
-
if ebk.length > 1
|
24
|
-
sexp << block
|
25
|
-
elsif ebk.length == 1
|
26
|
-
sexp << full_process(ebk[0])
|
27
|
-
end
|
28
|
-
sexp
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
# Returns a :block S-expression, the contents of the class.
|
34
|
-
def block
|
35
|
-
processed = @exp.block.map { |line| full_process(line) }
|
36
|
-
s(:block, *processed)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Given a `test_class_name` like `BananaTest`, returns the
|
40
|
-
# described class, like `Banana`.
|
41
|
-
def described_class(test_class_name)
|
42
|
-
test_class_name.to_s.gsub(/Test\Z/, '').to_sym
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns the head of the output Sexp. If it's a test case,
|
46
|
-
# an :iter representing an `RSpec.describe`. Otherwise, a :class.
|
47
|
-
def head
|
48
|
-
if @exp.test_case?
|
49
|
-
rspec_describe_block
|
50
|
-
else
|
51
|
-
s(:class, @exp.name, @exp.parent)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Returns an S-expression representing the
|
56
|
-
# RDM (RSpec Describe Metadata) hash
|
57
|
-
def rdm
|
58
|
-
s(:hash, s(:lit, :type), s(:lit, rdm_type))
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns the RDM (RSpec Describe Metadata) type.
|
62
|
-
#
|
63
|
-
# > Model specs: type: :model
|
64
|
-
# > Controller specs: type: :controller
|
65
|
-
# > Request specs: type: :request
|
66
|
-
# > Feature specs: type: :feature
|
67
|
-
# > View specs: type: :view
|
68
|
-
# > Helper specs: type: :helper
|
69
|
-
# > Mailer specs: type: :mailer
|
70
|
-
# > Routing specs: type: :routing
|
71
|
-
# > http://bit.ly/1G5w7CJ
|
72
|
-
#
|
73
|
-
# TODO: Obviously, they're not all supported yet.
|
74
|
-
def rdm_type
|
75
|
-
if @exp.action_controller_test_case?
|
76
|
-
:controller
|
77
|
-
elsif @exp.draper_test_case?
|
78
|
-
:decorator
|
79
|
-
elsif @exp.action_mailer_test_case?
|
80
|
-
:mailer
|
81
|
-
else
|
82
|
-
:model
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def rspec_describe
|
87
|
-
const = s(:const, described_class(@exp.name))
|
88
|
-
call = s(:call, s(:const, :RSpec), :describe, const)
|
89
|
-
call << rdm if @rails
|
90
|
-
call
|
91
|
-
end
|
92
|
-
|
93
|
-
# Returns a S-expression representing a call to RSpec.describe
|
94
|
-
def rspec_describe_block
|
95
|
-
s(:iter, rspec_describe, 0)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|