minitest_to_rspec 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7af6cefcb0786c8e45326f8620a786ad8f2fe89
4
- data.tar.gz: 67ca2d184a2ea2b98dda827c70e3a5fbaf44dfbe
3
+ metadata.gz: 265d35e67e77ee31bae7acc313f3968d07799e52
4
+ data.tar.gz: c7a5a26dfdb3d2e6275d702586ec319a125c5074
5
5
  SHA512:
6
- metadata.gz: 71242e74b6d2c4801191aa11e85214c8ab28b2390e265a9b043c22b64fa05a9ff2e238164c601081a6c89a347e1ae8b840e27541d495fc81f132527f6820c613
7
- data.tar.gz: d86f72884d87dba2b95b07132ab0e1a20ce463a4723056ff16c4292c0df2330bbc55e3552e45523521fff6e1ff99aa219b15d9a6f224fe798b8fe49c425a8205
6
+ metadata.gz: 7544fbb50ee02a275a0e9d8cda04d1d10b927a8431c7e99b1a2d1a5d60e497f8013e0b2915b9f45684ae160573df1a0b77e9db644bde40016f6dd1011d1becf7
7
+ data.tar.gz: fee5e6be9a7e20414b808c5a1f453a0bbea8c68cc5a01a7f50f3d53c3419d5494a8046e0a5485ee25c134e1753713700813c22cce4a1bca195eb0eeef90bc441
data/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ 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.6.0
8
+ -----
9
+
10
+ ### Added
11
+ - Converts
12
+ - Draper::TestCase
13
+ - ActionMailer::TestCase
14
+ - Experimental
15
+ - mocha: once, twice
16
+ - Switch from ruby2ruby to sexp2ruby
17
+ - Will have better output, e.g. ruby 1.9.3 hash syntax
18
+ - Upgrade to ruby_parser 3.7
19
+
7
20
  0.5.0
8
21
  -----
9
22
 
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in minitest_to_rspec.gemspec
4
4
  gemspec
5
+
6
+ # Required runtime dep: trollop > f7009b45,
7
+ # but gemspec does not support git :(
8
+ gem 'trollop', github: "ManageIQ/trollop"
data/README.md CHANGED
@@ -81,6 +81,8 @@ assert_nil | |
81
81
  refute | |
82
82
  refute_equal | |
83
83
 
84
+ To do: assert_not_nil
85
+
84
86
  Supported Mocha
85
87
  ---------------
86
88
 
@@ -88,17 +90,19 @@ Mocha | Arity | Block | Notes
88
90
  --------------------- | ----- | ----- | -------
89
91
  [any_instance][29] | 0 | n/a |
90
92
  [expects][21] | 1 | n/a |
93
+ [once][31] | 0 | n/a |
91
94
  [stub][19] | 0,1,2 | no |
92
95
  [stub_everything][18] | 0,1,2 | no | Uses `as_null_object`, not the same.
93
96
  [stubs][20] | 1 | n/a |
97
+ [twice][32] | 0 | n/a |
94
98
 
95
- Notably not supported yet: [at_least, once, never, raises, etc.][30]
99
+ To do: [at_least, never, raises, etc.][30]
96
100
 
97
101
  Acknowledgements
98
102
  ----------------
99
103
 
100
- Uses [ruby_parser][14], [sexp_processor][15], and [ruby2ruby][16]
101
- by [Ryan Davis][17].
104
+ This project would not be possible without [ruby_parser][14],
105
+ [sexp_processor][15], and [ruby2ruby][16] by [Ryan Davis][17].
102
106
 
103
107
  [1]: https://travis-ci.org/jaredbeck/minitest_to_rspec.svg
104
108
  [2]: https://travis-ci.org/jaredbeck/minitest_to_rspec
@@ -130,3 +134,5 @@ by [Ryan Davis][17].
130
134
  [28]: http://gofreerange.com/mocha/docs/
131
135
  [29]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/ClassMethods#any_instance-instance_method
132
136
  [30]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/Expectation
137
+ [31]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/Expectation#once-instance_method
138
+ [32]: http://www.rubydoc.info/github/floehopper/mocha/Mocha/Expectation#twice-instance_method
@@ -1,13 +1,6 @@
1
1
  require "minitest_to_rspec"
2
2
  require "trollop"
3
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
4
  module MinitestToRspec
12
5
  class CLI
13
6
  E_USAGE = 1.freeze
@@ -33,7 +26,10 @@ EOS
33
26
  attr_reader :rails, :source, :target
34
27
 
35
28
  def initialize(args)
29
+ assert_trollop_version
30
+
36
31
  opts = Trollop::options(args) do
32
+ educate_on_error
37
33
  version MinitestToRspec::VERSION
38
34
  banner BANNER
39
35
  opt :rails, OPT_RAILS, short: :none
@@ -47,8 +43,7 @@ EOS
47
43
  @source = args[0]
48
44
  @target = infer_target_from @source
49
45
  else
50
- Trollop.educate_without_exiting
51
- exit(E_USAGE)
46
+ Trollop.die("Please specify source file", nil, E_USAGE)
52
47
  end
53
48
  end
54
49
 
@@ -77,6 +72,17 @@ EOS
77
72
  end
78
73
  end
79
74
 
75
+ # Temporary assertion. It would be nice if gemspec supported git.
76
+ def assert_trollop_version
77
+ unless Trollop.method(:die).arity == -2
78
+ warn "Please use trollop version f7009b45 or greater."
79
+ warn "This manual version constraint will be removed when"
80
+ warn "https://github.com/ManageIQ/trollop/pull/63"
81
+ warn "is included in an official trollop release."
82
+ exit(-1)
83
+ end
84
+ end
85
+
80
86
  def converter
81
87
  Converter.new(rails: rails)
82
88
  end
@@ -1,5 +1,5 @@
1
1
  require "ruby_parser"
2
- require "ruby2ruby"
2
+ require "sexp2ruby"
3
3
  require_relative "processor"
4
4
  require_relative "errors"
5
5
 
@@ -16,28 +16,8 @@ module MinitestToRspec
16
16
 
17
17
  private
18
18
 
19
- # Parses an input string using the `ruby_parser` gem, and
20
- # returns an Abstract Syntax Tree (AST) in the form of
21
- # S-expressions.
22
- #
23
- # Example of AST
24
- # --------------
25
- #
26
- # s(:block,
27
- # s(:call, nil, :require, s(:str, "test_helper")),
28
- # s(:class,
29
- # :BananaTest,
30
- # s(:colon2, s(:const, :ActiveSupport), :TestCase),
31
- # s(:iter,
32
- # s(:call, nil, :test, s(:str, "is delicious")),
33
- # s(:args),
34
- # s(:call, nil, :assert,
35
- # s(:call, s(:call, s(:const, :Banana), :new), :delicious?)
36
- # )
37
- # )
38
- # )
39
- # )
40
- #
19
+ # Parses input string and returns Abstract Syntax Tree (AST)
20
+ # as an S-expression.
41
21
  def parse(input)
42
22
  RubyParser.new.parse(input)
43
23
  end
@@ -52,15 +32,11 @@ module MinitestToRspec
52
32
  # Given an AST representing an rspec file, returns a string
53
33
  # of ruby code.
54
34
  def render(exp)
55
- ruby2ruby.process(exp)
35
+ renderer.process(exp)
56
36
  end
57
37
 
58
- # Try to specify ruby 1.9 hash_syntax if ruby2ruby supports it.
59
- # https://github.com/seattlerb/ruby2ruby/pull/37
60
- def ruby2ruby
61
- Ruby2Ruby.new(hash_syntax: :ruby19)
62
- rescue ArgumentError
63
- Ruby2Ruby.new
38
+ def renderer
39
+ Sexp2Ruby::Processor.new(hash_syntax: :ruby19)
64
40
  end
65
41
  end
66
42
  end
@@ -94,6 +94,23 @@ module MinitestToRspec
94
94
  @exp[1]
95
95
  end
96
96
 
97
+ # While `#receiver` returns a `Sexp`, `#receiver_call`
98
+ # returns a `Exp::Call`.
99
+ def receiver_call
100
+ if sexp_type?(:call, receiver)
101
+ rvc = Exp::Call.new(receiver)
102
+
103
+ # TODO: Seems like a factory pattern
104
+ if rvc.method_name == :returns
105
+ Exp::Calls::Returns.new(receiver)
106
+ else
107
+ rvc
108
+ end
109
+ else
110
+ raise TypeError
111
+ end
112
+ end
113
+
97
114
  def require_test_helper?
98
115
  method_name == :require &&
99
116
  one_string_argument? &&
@@ -0,0 +1,11 @@
1
+ require_relative "../call"
2
+ require_relative "../../errors"
3
+
4
+ module MinitestToRspec
5
+ module Exp
6
+ module Calls
7
+ class Once < Call
8
+ end
9
+ end
10
+ end
11
+ end
@@ -65,14 +65,6 @@ module MinitestToRspec
65
65
  def values
66
66
  arguments
67
67
  end
68
-
69
- private
70
-
71
- # The receiver of the `:returns` message is a `:call`
72
- # either to `#stubs` or `#expects`.
73
- def receiver_call
74
- Call.new(receiver)
75
- end
76
68
  end
77
69
  end
78
70
  end
@@ -0,0 +1,11 @@
1
+ require_relative "../call"
2
+ require_relative "../../errors"
3
+
4
+ module MinitestToRspec
5
+ module Exp
6
+ module Calls
7
+ class Twice < Call
8
+ end
9
+ end
10
+ end
11
+ end
@@ -15,6 +15,10 @@ module MinitestToRspec
15
15
  lineage?(parent, [:ActionController, :TestCase])
16
16
  end
17
17
 
18
+ def action_mailer_test_case?
19
+ lineage?(parent, [:ActionMailer, :TestCase])
20
+ end
21
+
18
22
  def active_support_test_case?
19
23
  lineage?(parent, [:ActiveSupport, :TestCase])
20
24
  end
@@ -39,6 +43,10 @@ module MinitestToRspec
39
43
  @_block ||= @exp[3..-1] || []
40
44
  end
41
45
 
46
+ def draper_test_case?
47
+ lineage?(parent, [:Draper, :TestCase])
48
+ end
49
+
42
50
  # Returns the name of the class. Examples:
43
51
  #
44
52
  # - Banana #=> :Banana
@@ -66,7 +74,9 @@ module MinitestToRspec
66
74
  def test_case?
67
75
  return false unless sexp_type?(:colon2, parent)
68
76
  active_support_test_case? ||
69
- action_controller_test_case?
77
+ action_controller_test_case? ||
78
+ action_mailer_test_case? ||
79
+ draper_test_case?
70
80
  end
71
81
 
72
82
  private
@@ -47,7 +47,7 @@ module MinitestToRspec
47
47
  def expectation_target_lazy(block)
48
48
  s(:iter,
49
49
  s(:call, nil, :expect),
50
- s(:args),
50
+ 0,
51
51
  full_process(block)
52
52
  )
53
53
  end
@@ -31,6 +31,15 @@ module MinitestToRspec
31
31
  allow_to(msg_rcp, receive_and_return(msg, ret_vals), any_ins)
32
32
  end
33
33
 
34
+ # Given `exp`, an S-expression representing an rspec-mocks statement
35
+ # (expect or allow) apply `ordinal`, which is either `:once` or `:twice`.
36
+ # This feels like a hack. No other processing "re-opens" an "output
37
+ # sexp".
38
+ def apply_expectation_count_to(exp, ordinal)
39
+ exp[3] = s(:call, exp[3], ordinal)
40
+ exp
41
+ end
42
+
34
43
  def be_falsey
35
44
  matcher(:be_falsey)
36
45
  end
@@ -98,12 +107,16 @@ module MinitestToRspec
98
107
 
99
108
  def method_expects
100
109
  if @exp.num_arguments == 1
101
- mocha_expects
110
+ mocha_expects(@exp)
102
111
  else
103
112
  @exp.original
104
113
  end
105
114
  end
106
115
 
116
+ def method_once
117
+ mocha_once(@exp)
118
+ end
119
+
107
120
  def method_refute
108
121
  expect_to(be_falsey, @exp.arguments[0], true)
109
122
  end
@@ -136,11 +149,7 @@ module MinitestToRspec
136
149
  # - (name, stubs)
137
150
 
138
151
  def method_stub
139
- if @exp.receiver.nil?
140
- s(:call, nil, :double, *@exp.arguments)
141
- else
142
- @exp.original
143
- end
152
+ mocha_stub(@exp)
144
153
  end
145
154
 
146
155
  # [stub_everything][1] responds to all messages with nil.
@@ -162,30 +171,53 @@ module MinitestToRspec
162
171
  s(:call, nil, :it, *@exp.arguments)
163
172
  end
164
173
 
165
- def mocha_expects
166
- arg = @exp.arguments.first
174
+ def method_twice
175
+ mocha_twice(@exp)
176
+ end
177
+
178
+ def mocha_expects(exp)
179
+ raise ArgumentError unless exp.is_a?(Exp::Call)
180
+ arg = exp.arguments.first
167
181
  if sexp_type?(:hash, arg)
168
- mocha_expects_hash(arg)
182
+ mocha_expects_hash(exp, arg)
169
183
  elsif sexp_type?(:lit, arg)
170
- mocha_expects_lit(arg)
184
+ mocha_expects_lit(exp, arg)
171
185
  else
172
- @exp.original
186
+ exp.original
173
187
  end
174
188
  end
175
189
 
176
- def mocha_expects_hash(hash_sexp)
190
+ def mocha_expects_hash(exp, hash_sexp)
177
191
  assert_sexp_type(:hash, hash_sexp)
178
- pointless_lambda(hash_to_expectations(hash_sexp, @exp.receiver))
192
+ pointless_lambda(hash_to_expectations(hash_sexp, exp.receiver))
179
193
  end
180
194
 
181
- def mocha_expects_lit(lit_sexp)
195
+ def mocha_expects_lit(exp, lit_sexp)
182
196
  assert_sexp_type(:lit, lit_sexp)
183
- expect_to(receive_and_call_original(lit_sexp), @exp.receiver, true)
197
+ expect_to(receive_and_call_original(lit_sexp), exp.receiver, true)
198
+ end
199
+
200
+ def mocha_expectation_count(exp, ordinal)
201
+ raise ArgumentError unless exp.is_a?(Exp::Call)
202
+ raise ArgumentError unless %i[once twice].include?(ordinal)
203
+ rvc = exp.receiver_call
204
+ receiver_processing_method = "mocha_#{rvc.method_name}".to_sym
205
+ if respond_to?(receiver_processing_method, true)
206
+ x = send(receiver_processing_method, rvc)
207
+ apply_expectation_count_to(x, ordinal)
208
+ else
209
+ exp.original
210
+ end
211
+ end
212
+
213
+ def mocha_once(exp)
214
+ mocha_expectation_count(exp, :once)
184
215
  end
185
216
 
186
217
  # Given `r`, a `Exp::Calls::Returns`, return a `Sexp` representing
187
218
  # the equivalent stub or message expectation in RSpec.
188
219
  def mocha_returns(r)
220
+ raise ArgumentError unless r.is_a?(Exp::Calls::Returns)
189
221
  subprocessor_method = "#{r.rspec_mocks_method}_receive_and_return"
190
222
  send(subprocessor_method,
191
223
  r.rspec_msg_recipient,
@@ -195,6 +227,19 @@ module MinitestToRspec
195
227
  )
196
228
  end
197
229
 
230
+ def mocha_stub(exp)
231
+ raise ArgumentError unless exp.is_a?(Exp::Call)
232
+ if exp.receiver.nil?
233
+ s(:call, nil, :double, *exp.arguments)
234
+ else
235
+ exp.original
236
+ end
237
+ end
238
+
239
+ def mocha_twice(exp)
240
+ mocha_expectation_count(exp, :twice)
241
+ end
242
+
198
243
  def name_of_processing_method
199
244
  "method_#{@exp.method_name}".to_sym
200
245
  end
@@ -220,7 +265,7 @@ module MinitestToRspec
220
265
  s(:call,
221
266
  s(:iter,
222
267
  s(:call, nil, :lambda),
223
- s(:args),
268
+ 0,
224
269
  s(:block,
225
270
  s(:str, "Sorry for the pointless lambda here."),
226
271
  *array_of_calls
@@ -33,7 +33,7 @@ module MinitestToRspec
33
33
  def matcher_with_block(matcher_name, block)
34
34
  s(:iter,
35
35
  s(:call, nil, matcher_name),
36
- s(:args),
36
+ 0,
37
37
  block
38
38
  )
39
39
  end
@@ -17,7 +17,12 @@ module MinitestToRspec
17
17
 
18
18
  def process
19
19
  sexp = head
20
- sexp << block if @exp.block?
20
+ ebk = @exp.block
21
+ if ebk.length > 1
22
+ sexp << block
23
+ elsif ebk.length == 1
24
+ sexp << full_process(ebk[0])
25
+ end
21
26
  sexp
22
27
  end
23
28
 
@@ -66,6 +71,10 @@ module MinitestToRspec
66
71
  def rdm_type
67
72
  if @exp.action_controller_test_case?
68
73
  :controller
74
+ elsif @exp.draper_test_case?
75
+ :decorator
76
+ elsif @exp.action_mailer_test_case?
77
+ :mailer
69
78
  else
70
79
  :model
71
80
  end
@@ -80,7 +89,7 @@ module MinitestToRspec
80
89
 
81
90
  # Returns a S-expression representing a call to RSpec.describe
82
91
  def rspec_describe_block
83
- s(:iter, rspec_describe, s(:args))
92
+ s(:iter, rspec_describe, 0)
84
93
  end
85
94
  end
86
95
  end
@@ -1,3 +1,3 @@
1
1
  module MinitestToRspec
2
- VERSION = "0.5.0".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
@@ -25,9 +25,12 @@ ruby2ruby.
25
25
  spec.require_paths = ["lib"]
26
26
  spec.required_ruby_version = ">= 2.0.0"
27
27
 
28
- spec.add_runtime_dependency "ruby_parser", "~> 3.6"
29
- spec.add_runtime_dependency "ruby2ruby", "~> 2.1"
30
- spec.add_runtime_dependency "trollop", "~> 2.1"
28
+ spec.add_runtime_dependency "ruby_parser", "~> 3.7"
29
+ spec.add_runtime_dependency "sexp2ruby", "~> 0.0.2"
30
+
31
+ # Required runtime dep: trollop > f7009b45,
32
+ # but gemspec does not support git :(
33
+ # spec.add_runtime_dependency "trollop", "~> 2.1"
31
34
 
32
35
  spec.add_development_dependency "bundler", "~> 1.7"
33
36
  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.5.0
4
+ version: 0.6.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-05-09 00:00:00.000000000 Z
11
+ date: 2015-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_parser
@@ -16,42 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.6'
19
+ version: '3.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.6'
26
+ version: '3.7'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby2ruby
28
+ name: sexp2ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: 0.0.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
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'
40
+ version: 0.0.2
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -182,7 +168,9 @@ files:
182
168
  - lib/minitest_to_rspec/errors.rb
183
169
  - lib/minitest_to_rspec/exp/base.rb
184
170
  - lib/minitest_to_rspec/exp/call.rb
171
+ - lib/minitest_to_rspec/exp/calls/once.rb
185
172
  - lib/minitest_to_rspec/exp/calls/returns.rb
173
+ - lib/minitest_to_rspec/exp/calls/twice.rb
186
174
  - lib/minitest_to_rspec/exp/hash_exp.rb
187
175
  - lib/minitest_to_rspec/exp/iter.rb
188
176
  - lib/minitest_to_rspec/exp/klass.rb