class MinitestToRspec::Input::Subprocessors::Iter
Processes `s(:iter, ..)` expressions.
Public Class Methods
new(sexp, rails, mocha)
click to toggle source
Calls superclass method
MinitestToRspec::Input::Subprocessors::Base::new
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 11 def initialize(sexp, rails, mocha) super(rails, mocha) @exp = Model::Iter.new(sexp) sexp.clear end
Public Instance Methods
process()
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 17 def process process_exp(@exp) end
Private Instance Methods
change(exp)
click to toggle source
Returns an expression representing an RSpec `change {}` matcher. See also `change_by` below.
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 25 def change(exp) matcher_with_block(:change, exp) end
change_by(diff_exp, by_exp)
click to toggle source
Returns an expression representing an RSpec `change {}.by()` matcher.
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 30 def change_by(diff_exp, by_exp) s(:call, change(diff_exp), :by, by_exp ) end
matcher_with_block(matcher_name, block)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 38 def matcher_with_block(matcher_name, block) s(:iter, s(:call, nil, matcher_name), 0, block ) end
method_assert_difference(exp)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 46 def method_assert_difference(exp) call = exp[1] block = exp[3] by = call[4] what = parse(call[3][1]) matcher = by.nil? ? change(what) : change_by(what, by) expect_to(matcher, block, false) end
method_assert_no_difference(exp)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 55 def method_assert_no_difference(exp) call = exp[1] block = exp[3] what = parse(call[3][1]) expect_to_not(change(what), block, false) end
method_assert_nothing_raised(exp)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 62 def method_assert_nothing_raised(exp) block = exp[3] expect_to_not(raise_error, block, false) end
method_assert_raise(iter)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 67 def method_assert_raise(iter) method_assert_raises(iter) end
method_assert_raises(iter)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 71 def method_assert_raises(iter) expect_to(raise_error(*iter.call_arguments), iter.block, false) end
method_refute_raise(iter)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 75 def method_refute_raise(iter) method_refute_raises(iter) end
method_refute_raises(iter)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 79 def method_refute_raises(iter) expect_to_not(raise_error(*iter.call_arguments), iter.block, false) end
method_setup(exp)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 83 def method_setup(exp) replace_method_name(exp, :before) end
method_teardown(exp)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 87 def method_teardown(exp) replace_method_name(exp, :after) end
name_of_processing_method(iter)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 91 def name_of_processing_method(iter) method_name = iter[1][2] "method_#{method_name}".to_sym end
parse(str)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 96 def parse(str) RubyParser.new.parse(str) end
process_exp(exp)
click to toggle source
Given a `Model::Iter`, returns a `Sexp`
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 101 def process_exp(exp) if processable?(exp) send_to_processing_method(exp) else process_uninteresting_iter(exp.sexp) end end
process_uninteresting_iter(exp)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 119 def process_uninteresting_iter(exp) iter = s(exp.shift) until exp.empty? iter << full_process(exp.shift) end iter end
processable?(iter)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 109 def processable?(iter) if !iter.empty? && iter[1].sexp_type == :call method_name = iter[1][2] decision = "#{method_name}?".to_sym iter.respond_to?(decision) && iter.public_send(decision) else false end end
raise_error(*args)
click to toggle source
Given `args` which came from an `assert_raise` or an `assert_raises`, return a `raise_error` matcher. When the last argument is a string, it represents the assertion failure message, and is discarded.
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 131 def raise_error(*args) args.pop if !args.empty? && args.last.sexp_type == :str matcher(:raise_error, *args) end
replace_method_name(exp, new_method)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 136 def replace_method_name(exp, new_method) iter = s(:iter, s(:call, nil, new_method)) exp.each do |e| iter << full_process(e) end iter end
send_to_processing_method(exp)
click to toggle source
# File lib/minitest_to_rspec/input/subprocessors/iter.rb, line 142 def send_to_processing_method(exp) send(name_of_processing_method(exp), exp) end