Class: MinitestToRspec::Input::Subprocessors::Defn

Inherits:
Base
  • Object
show all
Defined in:
lib/minitest_to_rspec/input/subprocessors/defn.rb

Overview

Minitest tests can be defined as methods using names beginning with ‘test_’. Process those tests into RSpec ‘it` example blocks.

Instance Method Summary collapse

Methods inherited from Base

#allow_to, #expect, #expect_to, #expect_to_not, #expectation_target, #expectation_target_eager, #expectation_target_lazy, #full_process, #matcher

Methods included from SexpAssertions

#assert_sexp_type, #assert_sexp_type_array, #sexp_type?

Constructor Details

#initialize(sexp, rails, mocha) ⇒ Defn

Returns a new instance of Defn.



13
14
15
16
17
18
# File 'lib/minitest_to_rspec/input/subprocessors/defn.rb', line 13

def initialize(sexp, rails, mocha)
  super(rails, mocha)
  @original = sexp.dup
  @exp = Model::Defn.new(sexp)
  sexp.clear
end

Instance Method Details

#processObject

Using a ‘Model::Defn`, returns a `Sexp`



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/minitest_to_rspec/input/subprocessors/defn.rb', line 21

def process
  if @exp.test_method?
    s(:iter,
      s(:call, nil, :it, s(:str, example_title)),
      0,
      example_block)
  elsif @exp.setup?
    s(:iter,
      s(:call, nil, :before),
      0,
      example_block
    )
  elsif @exp.teardown?
    s(:iter,
      s(:call, nil, :after),
      0,
      example_block
    )
  else
    @original
  end
end