minitest_to_rspec 0.3.0 → 0.4.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 +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +12 -0
- data/README.md +37 -16
- data/lib/minitest_to_rspec/errors.rb +9 -0
- data/lib/minitest_to_rspec/exp/call.rb +4 -0
- data/lib/minitest_to_rspec/exp/calls/returns.rb +43 -11
- data/lib/minitest_to_rspec/exp/hash_exp.rb +19 -0
- data/lib/minitest_to_rspec/sexp_assertions.rb +6 -0
- data/lib/minitest_to_rspec/subprocessors/base.rb +31 -20
- data/lib/minitest_to_rspec/subprocessors/call.rb +116 -8
- data/lib/minitest_to_rspec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a27f05346fd70cc99e4153026b9fbbfec34c534
|
4
|
+
data.tar.gz: 56cb0bab1016ecde051d2fcb92f6142d2009c063
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f17804b35926a1820f7f521b421bf27a6840afa78a7c6fef1e3ceb97523b19d451ea749b7af3445904448f0a76d805faba95291a49b4b44251486ad0707dbe95
|
7
|
+
data.tar.gz: aee5ab8d4f585ac6a3798002400072278e0abf3b1d28a90fb6dcaf599424308b6d9d5907e75ef02b247f416827281fe7c713d6661a76395aa700d9482bde8870
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,18 @@ 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.4.0
|
8
|
+
-----
|
9
|
+
|
10
|
+
### Added
|
11
|
+
- Experimental
|
12
|
+
- Conversion of mocha to rspec-mocks
|
13
|
+
- expects
|
14
|
+
- any_instance
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- NoMethodError when input contains stabby lambda
|
18
|
+
|
7
19
|
0.3.0
|
8
20
|
-----
|
9
21
|
|
data/README.md
CHANGED
@@ -4,8 +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
|
-
|
8
|
-
|
7
|
+
Selected assertions from [Test::Unit][26], [minitest][8], and
|
8
|
+
[ActiveSupport][27] are converted to [rspec-expectations][25].
|
9
|
+
Selected methods from [mocha][28] are converted to [rspec-mocks][24].
|
9
10
|
|
10
11
|
Example
|
11
12
|
-------
|
@@ -14,11 +15,12 @@ Input:
|
|
14
15
|
|
15
16
|
```ruby
|
16
17
|
require 'test_helper'
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
class ArrayTest < ActiveSupport::TestCase
|
19
|
+
test "changes length" do
|
20
|
+
ary = []
|
21
|
+
assert_difference "ary.length" do
|
22
|
+
ary.push(:x)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
```
|
@@ -27,16 +29,16 @@ Output:
|
|
27
29
|
|
28
30
|
```ruby
|
29
31
|
require("spec_helper")
|
30
|
-
RSpec.describe(
|
31
|
-
it("
|
32
|
+
RSpec.describe(Array) do
|
33
|
+
it("changes length") do
|
34
|
+
ary = []
|
35
|
+
expect { ary.push(:x) }.to(change { ary.length })
|
36
|
+
end
|
32
37
|
end
|
33
38
|
```
|
34
39
|
|
35
|
-
[RubyParser][14] discards all comments.
|
36
|
-
|
37
40
|
The code style is whatever [ruby2ruby][6] feels like printing,
|
38
|
-
and is not configurable.
|
39
|
-
rspec quickly.
|
41
|
+
and is not configurable. Comments are discarded.
|
40
42
|
|
41
43
|
Usage
|
42
44
|
-----
|
@@ -45,7 +47,7 @@ Usage
|
|
45
47
|
|
46
48
|
```bash
|
47
49
|
gem install minitest_to_rspec
|
48
|
-
minitest_to_rspec --rails source_file target_file
|
50
|
+
bundle exec minitest_to_rspec --rails source_file target_file
|
49
51
|
```
|
50
52
|
|
51
53
|
### Ruby
|
@@ -67,7 +69,8 @@ Assertion | Arity | Source
|
|
67
69
|
--------------------------- | ----- | ------
|
68
70
|
assert | |
|
69
71
|
assert_difference | 1,2 |
|
70
|
-
assert_equal
|
72
|
+
[assert_equal][23] | 2,3 | Test::Unit
|
73
|
+
[assert_not_equal][22] | 2,3 | Test::Unit
|
71
74
|
assert_match | |
|
72
75
|
assert_nil | |
|
73
76
|
[assert_no_difference][12] | | ActiveSupport
|
@@ -82,11 +85,19 @@ Supported Mocha
|
|
82
85
|
|
83
86
|
Mocha | Arity | Block | Notes
|
84
87
|
--------------------- | ----- | ----- | -------
|
88
|
+
[any_instance][29] | 0 | n/a |
|
89
|
+
[expects][21] | 1 | n/a |
|
85
90
|
[stub][19] | 0,1,2 | no |
|
86
91
|
[stub_everything][18] | 0,1,2 | no | Uses `as_null_object`, not the same.
|
87
92
|
[stubs][20] | 1 | n/a |
|
88
93
|
|
89
|
-
Notably not yet
|
94
|
+
Notably not supported yet: [at_least, once, never, raises, etc.][30]
|
95
|
+
|
96
|
+
Acknowledgements
|
97
|
+
----------------
|
98
|
+
|
99
|
+
Uses [ruby_parser][14], [sexp_processor][15], and [ruby2ruby][16]
|
100
|
+
by [Ryan Davis][17].
|
90
101
|
|
91
102
|
[1]: https://travis-ci.org/jaredbeck/minitest_to_rspec.svg
|
92
103
|
[2]: https://travis-ci.org/jaredbeck/minitest_to_rspec
|
@@ -108,3 +119,13 @@ Notably not yet supported: `expects`, `any_instance`
|
|
108
119
|
[18]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/API:stub_everything
|
109
120
|
[19]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/API#stub-instance_method
|
110
121
|
[20]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/ObjectMethods#stubs-instance_method
|
122
|
+
[21]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/ObjectMethods:expects
|
123
|
+
[22]: http://www.rubydoc.info/gems/test-unit/3.0.9/Test/Unit/Assertions#assert_not_equal-instance_method
|
124
|
+
[23]: http://www.rubydoc.info/gems/test-unit/3.0.9/Test/Unit/Assertions#assert_equal-instance_method
|
125
|
+
[24]: https://github.com/rspec/rspec-mocks
|
126
|
+
[25]: https://github.com/rspec/rspec-expectations
|
127
|
+
[26]: http://test-unit.github.io/
|
128
|
+
[27]: https://rubygems.org/gems/activesupport
|
129
|
+
[28]: http://gofreerange.com/mocha/docs/
|
130
|
+
[29]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/ClassMethods#any_instance-instance_method
|
131
|
+
[30]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/Expectation
|
@@ -1,6 +1,15 @@
|
|
1
1
|
module MinitestToRspec
|
2
2
|
class Error < StandardError; end
|
3
3
|
class ProcessingError < Error; end
|
4
|
+
|
5
|
+
# Raise `UnknownVariant` to indicate that an expression is
|
6
|
+
# not recognized. This exception should always be rescued,
|
7
|
+
# and the original expression should be used in the output.
|
8
|
+
class UnknownVariant < Error; end
|
9
|
+
|
10
|
+
# Raise `NotImplemented` to indicate that an expression is
|
11
|
+
# recognized (not an `UnknownVariant`) but that `minitest_to_rspec`
|
12
|
+
# does not (yet) implement a conversion.
|
4
13
|
class NotImplemented < Error; end
|
5
14
|
|
6
15
|
class ModuleShorthandError < NotImplemented
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require_relative "../call"
|
2
|
+
require_relative "../../errors"
|
3
|
+
|
1
4
|
module MinitestToRspec
|
2
5
|
module Exp
|
3
6
|
module Calls
|
@@ -5,23 +8,57 @@ module MinitestToRspec
|
|
5
8
|
# Represents a call to `returns`, the stubbing method
|
6
9
|
# from `mocha`.
|
7
10
|
class Returns < Call
|
11
|
+
KNOWN_RECEIVERS = %i[stubs expects]
|
12
|
+
RSPEC_MOCK_METHODS = { expects: :expect, stubs: :allow }
|
13
|
+
|
8
14
|
def initialize(exp)
|
9
15
|
@exp = exp
|
16
|
+
raise UnknownVariant unless known_variant?
|
17
|
+
end
|
18
|
+
|
19
|
+
def any_instance?
|
20
|
+
rcr = receiver_call.receiver
|
21
|
+
if !rcr.nil? && sexp_type?(:call, rcr)
|
22
|
+
Call.new(rcr).method_name == :any_instance
|
23
|
+
else
|
24
|
+
false
|
25
|
+
end
|
10
26
|
end
|
11
27
|
|
12
28
|
# The message recipient
|
13
29
|
def msg_recipient
|
14
|
-
|
30
|
+
receiver_call.receiver
|
15
31
|
end
|
16
32
|
|
17
33
|
def known_variant?
|
18
|
-
|
34
|
+
r = receiver
|
35
|
+
!r.nil? &&
|
36
|
+
r.sexp_type == :call &&
|
37
|
+
KNOWN_RECEIVERS.include?(Call.new(r).method_name) &&
|
19
38
|
!values.empty? &&
|
20
39
|
message.sexp_type == :lit
|
21
40
|
end
|
22
41
|
|
23
42
|
def message
|
24
|
-
|
43
|
+
receiver_call.arguments[0]
|
44
|
+
end
|
45
|
+
|
46
|
+
# To avoid a `ProcessingError` please check `known_variant?`
|
47
|
+
# before calling `rspec_mocks_method`.
|
48
|
+
def rspec_mocks_method
|
49
|
+
RSPEC_MOCK_METHODS[receiver_call.method_name]
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns `Sexp` representing the object that will receive
|
53
|
+
# the stubbed message. Examples:
|
54
|
+
#
|
55
|
+
# banana.stubs(:delicious?).returns(true)
|
56
|
+
# Kiwi.any_instance.stubs(:delicious?).returns(false)
|
57
|
+
#
|
58
|
+
# The `rspec_msg_recipient` is `banana` and `Kiwi`, respectively.
|
59
|
+
#
|
60
|
+
def rspec_msg_recipient
|
61
|
+
any_instance? ? Call.new(msg_recipient).receiver : msg_recipient
|
25
62
|
end
|
26
63
|
|
27
64
|
# The return values
|
@@ -31,14 +68,9 @@ module MinitestToRspec
|
|
31
68
|
|
32
69
|
private
|
33
70
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
r.sexp_type == :call &&
|
38
|
-
Call.new(r).method_name == :stubs
|
39
|
-
end
|
40
|
-
|
41
|
-
def stubs_call
|
71
|
+
# The receiver of the `:returns` message is a `:call`
|
72
|
+
# either to `#stubs` or `#expects`.
|
73
|
+
def receiver_call
|
42
74
|
Call.new(receiver)
|
43
75
|
end
|
44
76
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MinitestToRspec
|
2
|
+
module Exp
|
3
|
+
|
4
|
+
# Data object. Represents a `:hash` S-expression.
|
5
|
+
class HashExp < Base
|
6
|
+
def initialize(sexp)
|
7
|
+
assert_sexp_type(:hash, sexp)
|
8
|
+
@exp = sexp.dup
|
9
|
+
end
|
10
|
+
|
11
|
+
# A slightly nicer implementation would be:
|
12
|
+
# `@exp[1..-1].each_slice(2).to_h`
|
13
|
+
# but that would require ruby >= 2.1
|
14
|
+
def to_h
|
15
|
+
Hash[@exp[1..-1].each_slice(2).to_a]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -2,6 +2,12 @@ module MinitestToRspec
|
|
2
2
|
|
3
3
|
# Useful runtime assertions regarding S-expressions.
|
4
4
|
module SexpAssertions
|
5
|
+
def assert_sexp_type_array(type, obj)
|
6
|
+
unless obj.is_a?(Array) && obj.all? { |x| sexp_type?(type, x) }
|
7
|
+
raise TypeError, "Expected array of #{type} sexp, got #{obj.inspect}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def assert_sexp_type(type, exp)
|
6
12
|
unless sexp_type?(type, exp)
|
7
13
|
raise TypeError, "Expected #{type} s-expression, got #{exp.inspect}"
|
@@ -6,36 +6,42 @@ module MinitestToRspec
|
|
6
6
|
include SexpAssertions
|
7
7
|
|
8
8
|
# Returns a s-expression representing an rspec-mocks stub.
|
9
|
-
def allow_to(msg_recipient, matcher)
|
10
|
-
|
9
|
+
def allow_to(msg_recipient, matcher, any_instance = false)
|
10
|
+
allow_method = any_instance ? :allow_any_instance_of : :allow
|
11
|
+
target = s(:call, nil, allow_method, msg_recipient)
|
11
12
|
s(:call, target, :to, matcher)
|
12
13
|
end
|
13
14
|
|
14
15
|
# Returns a s-expression representing an RSpec expectation, i.e. the
|
15
16
|
# combination of an "expectation target" and a matcher.
|
16
|
-
def expect(target, eager, phase, matcher)
|
17
|
-
|
17
|
+
def expect(target, eager, phase, matcher, any_instance)
|
18
|
+
et = expectation_target(target, eager, any_instance)
|
19
|
+
s(:call, et, phase, matcher)
|
18
20
|
end
|
19
21
|
|
20
|
-
def expect_to(matcher, target, eager)
|
21
|
-
expect(target, eager, :to, matcher)
|
22
|
+
def expect_to(matcher, target, eager, any_instance = false)
|
23
|
+
expect(target, eager, :to, matcher, any_instance)
|
22
24
|
end
|
23
25
|
|
24
26
|
def expect_to_not(matcher, target, eager)
|
25
|
-
expect(target, eager, :to_not, matcher)
|
27
|
+
expect(target, eager, :to_not, matcher, false)
|
26
28
|
end
|
27
29
|
|
28
30
|
# In RSpec, `expect` returns an "expectation target". This
|
29
31
|
# can be based on an expression, as in `expect(1 + 1)` or it
|
30
32
|
# can be based on a block, as in `expect { raise }`. Either
|
31
33
|
# way, it's called an "expectation target".
|
32
|
-
def expectation_target(exp, eager
|
33
|
-
|
34
|
-
|
34
|
+
def expectation_target(exp, eager, any_instance)
|
35
|
+
if eager
|
36
|
+
expectation_target_eager(exp, any_instance)
|
37
|
+
else
|
38
|
+
expectation_target_lazy(exp)
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
|
-
def expectation_target_eager(exp)
|
38
|
-
|
42
|
+
def expectation_target_eager(exp, any_instance)
|
43
|
+
expect_method = any_instance ? :expect_any_instance_of : :expect
|
44
|
+
s(:call, nil, expect_method, exp)
|
39
45
|
end
|
40
46
|
|
41
47
|
def expectation_target_lazy(block)
|
@@ -46,14 +52,19 @@ module MinitestToRspec
|
|
46
52
|
)
|
47
53
|
end
|
48
54
|
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
|
56
|
-
|
55
|
+
# If it's a `Sexp`, run `obj` through a new `Processor`. Otherwise,
|
56
|
+
# return `obj`.
|
57
|
+
#
|
58
|
+
# This is useful for expressions that cannot be fully understood by a
|
59
|
+
# single subprocessor. For example, we must begin processing all :iter
|
60
|
+
# expressions, because some :iter represent calls we're interested in,
|
61
|
+
# e.g. `assert_difference`. However, if the :iter turns out to be
|
62
|
+
# uninteresting (perhaps it has no assertions) we still want to fully
|
63
|
+
# process its sub-expressions.
|
64
|
+
#
|
65
|
+
# TODO: `full_process` may not be the best name.
|
66
|
+
def full_process(obj)
|
67
|
+
obj.is_a?(Sexp) ? Processor.new(false).process(obj) : obj
|
57
68
|
end
|
58
69
|
|
59
70
|
def matcher(name, *args)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative "../exp/call"
|
2
2
|
require_relative "../exp/calls/returns"
|
3
|
+
require_relative "../exp/hash_exp"
|
3
4
|
require_relative "base"
|
4
5
|
|
5
6
|
module MinitestToRspec
|
@@ -22,8 +23,12 @@ module MinitestToRspec
|
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
# - msg_rcp. Message recipient. The object to be stubbed.
|
27
|
+
# - msg. Message. The name of the stubbed method.
|
28
|
+
# - ret_vals. Return values.
|
29
|
+
# - any_ins. Any instance? True if this is an `any_instance` stub.
|
30
|
+
def allow_receive_and_return(msg_rcp, msg, ret_vals, any_ins = false)
|
31
|
+
allow_to(msg_rcp, receive_and_return(msg, ret_vals), any_ins)
|
27
32
|
end
|
28
33
|
|
29
34
|
def be_falsey
|
@@ -42,6 +47,25 @@ module MinitestToRspec
|
|
42
47
|
matcher(:eq, exp)
|
43
48
|
end
|
44
49
|
|
50
|
+
# - msg_rcp. Message recipient. The object to be stubbed.
|
51
|
+
# - msg. Message. The name of the stubbed method.
|
52
|
+
# - ret_vals. Return values.
|
53
|
+
# - any_ins. Any instance? True if this is an `any_instance` stub.
|
54
|
+
def expect_receive_and_return(msg_rcp, msg, ret_vals, any_ins = false)
|
55
|
+
expect_to(receive_and_return(msg, ret_vals), msg_rcp, true, any_ins)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Given a `Sexp` representing a `Hash` of message expectations,
|
59
|
+
# return an array of `Sexp`, each representing an expectation
|
60
|
+
# in rspec-mocks syntax.
|
61
|
+
def hash_to_expectations(sexp, receiver)
|
62
|
+
Exp::HashExp.new(sexp).to_h.map { |msg, ret_val|
|
63
|
+
expect_receive_and_return(
|
64
|
+
receiver.deep_clone, msg, wrap_sexp(ret_val)
|
65
|
+
)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
45
69
|
def match(pattern)
|
46
70
|
matcher(:match, pattern)
|
47
71
|
end
|
@@ -66,6 +90,20 @@ module MinitestToRspec
|
|
66
90
|
expect_to(be_nil, @exp.arguments[0], true)
|
67
91
|
end
|
68
92
|
|
93
|
+
def method_assert_not_equal
|
94
|
+
expected = @exp.arguments[0]
|
95
|
+
calculated = @exp.arguments[1]
|
96
|
+
expect_to_not(eq(expected), calculated, true)
|
97
|
+
end
|
98
|
+
|
99
|
+
def method_expects
|
100
|
+
if @exp.num_arguments == 1
|
101
|
+
mocha_expects
|
102
|
+
else
|
103
|
+
@exp.original
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
69
107
|
def method_refute
|
70
108
|
expect_to(be_falsey, @exp.arguments[0], true)
|
71
109
|
end
|
@@ -77,12 +115,9 @@ module MinitestToRspec
|
|
77
115
|
end
|
78
116
|
|
79
117
|
def method_returns
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
else
|
84
|
-
@exp.original
|
85
|
-
end
|
118
|
+
mocha_returns(Exp::Calls::Returns.new(@exp.original))
|
119
|
+
rescue UnknownVariant
|
120
|
+
@exp.original
|
86
121
|
end
|
87
122
|
|
88
123
|
def method_require
|
@@ -127,14 +162,82 @@ module MinitestToRspec
|
|
127
162
|
s(:call, nil, :it, *@exp.arguments)
|
128
163
|
end
|
129
164
|
|
165
|
+
def mocha_expects
|
166
|
+
arg = @exp.arguments.first
|
167
|
+
if sexp_type?(:hash, arg)
|
168
|
+
mocha_expects_hash(arg)
|
169
|
+
elsif sexp_type?(:lit, arg)
|
170
|
+
mocha_expects_lit(arg)
|
171
|
+
else
|
172
|
+
@exp.original
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def mocha_expects_hash(hash_sexp)
|
177
|
+
assert_sexp_type(:hash, hash_sexp)
|
178
|
+
pointless_lambda(hash_to_expectations(hash_sexp, @exp.receiver))
|
179
|
+
end
|
180
|
+
|
181
|
+
def mocha_expects_lit(lit_sexp)
|
182
|
+
assert_sexp_type(:lit, lit_sexp)
|
183
|
+
expect_to(receive_and_call_original(lit_sexp), @exp.receiver, true)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Given `r`, a `Exp::Calls::Returns`, return a `Sexp` representing
|
187
|
+
# the equivalent stub or message expectation in RSpec.
|
188
|
+
def mocha_returns(r)
|
189
|
+
subprocessor_method = "#{r.rspec_mocks_method}_receive_and_return"
|
190
|
+
send(subprocessor_method,
|
191
|
+
r.rspec_msg_recipient,
|
192
|
+
r.message,
|
193
|
+
r.values,
|
194
|
+
r.any_instance?
|
195
|
+
)
|
196
|
+
end
|
197
|
+
|
130
198
|
def name_of_processing_method
|
131
199
|
"method_#{@exp.method_name}".to_sym
|
132
200
|
end
|
133
201
|
|
202
|
+
# Given `array_of_calls`, returns a `Sexp` representing a
|
203
|
+
# self-executing lambda.
|
204
|
+
#
|
205
|
+
# This works around the fact that `sexp_processor` expects us to return
|
206
|
+
# a single `Sexp`, not an array of `Sexp`. We also can't return a
|
207
|
+
# `:block`, or else certain input would produce nested blocks (e.g.
|
208
|
+
# `s(:block, s(:block, ..))`) which `ruby2ruby` (naturally) does not know
|
209
|
+
# how to process. So, the easiest solution I could think of is a
|
210
|
+
# self-executing lambda.
|
211
|
+
#
|
212
|
+
# Currently, the only `:call` which we process into multiple calls is
|
213
|
+
# the hash form of a mocha `#expects`, thankfully uncommon.
|
214
|
+
#
|
215
|
+
# To get better output (without a pointless lambda) we would have to
|
216
|
+
# process `:block` *and* `:defn`, which we are not yet doing.
|
217
|
+
|
218
|
+
def pointless_lambda(array_of_calls)
|
219
|
+
assert_sexp_type_array(:call, array_of_calls)
|
220
|
+
s(:call,
|
221
|
+
s(:iter,
|
222
|
+
s(:call, nil, :lambda),
|
223
|
+
s(:args),
|
224
|
+
s(:block,
|
225
|
+
s(:str, "Sorry for the pointless lambda here."),
|
226
|
+
*array_of_calls
|
227
|
+
)
|
228
|
+
),
|
229
|
+
:call
|
230
|
+
)
|
231
|
+
end
|
232
|
+
|
134
233
|
def receive(message)
|
135
234
|
s(:call, nil, :receive, message)
|
136
235
|
end
|
137
236
|
|
237
|
+
def receive_and_call_original(message)
|
238
|
+
s(:call, s(:call, nil, :receive, message), :and_call_original)
|
239
|
+
end
|
240
|
+
|
138
241
|
def receive_and_return(message, return_values)
|
139
242
|
s(:call, receive(message), :and_return, *return_values)
|
140
243
|
end
|
@@ -143,6 +246,11 @@ module MinitestToRspec
|
|
143
246
|
prefix = @rails ? "rails" : "spec"
|
144
247
|
s(:call, nil, :require, s(:str, "#{prefix}_helper"))
|
145
248
|
end
|
249
|
+
|
250
|
+
# Wraps `obj` in an `Array` if it is a `Sexp`
|
251
|
+
def wrap_sexp(obj)
|
252
|
+
obj.is_a?(Sexp) ? [obj] : obj
|
253
|
+
end
|
146
254
|
end
|
147
255
|
end
|
148
256
|
end
|
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.4.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-04-
|
11
|
+
date: 2015-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_parser
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/minitest_to_rspec/exp/base.rb
|
169
169
|
- lib/minitest_to_rspec/exp/call.rb
|
170
170
|
- lib/minitest_to_rspec/exp/calls/returns.rb
|
171
|
+
- lib/minitest_to_rspec/exp/hash_exp.rb
|
171
172
|
- lib/minitest_to_rspec/exp/iter.rb
|
172
173
|
- lib/minitest_to_rspec/exp/klass.rb
|
173
174
|
- lib/minitest_to_rspec/processor.rb
|