class MinitestToRspec::Input::Model::Call
Data object. Represents a `:call` s-expression.
Attributes
original[R]
Public Class Methods
assert_difference?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 19 def assert_difference?(exp) exp.sexp_type == :call && new(exp).assert_difference? end
assert_no_difference?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 23 def assert_no_difference?(exp) exp.sexp_type == :call && new(exp).assert_no_difference? end
assert_nothing_raised?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 27 def assert_nothing_raised?(exp) exp.sexp_type == :call && new(exp).assert_nothing_raised? end
assert_raise?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 31 def assert_raise?(exp) exp.sexp_type == :call && new(exp).assert_raise? end
assert_raises?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 35 def assert_raises?(exp) exp.sexp_type == :call && new(exp).assert_raises? end
method_name?(exp, name)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 47 def method_name?(exp, name) exp.sexp_type == :call && new(exp).method_name.to_s == name.to_s end
new(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 12 def initialize(exp) assert_sexp_type(:call, exp) @exp = exp.dup @original = exp.dup end
refute_raise?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 39 def refute_raise?(exp) exp.sexp_type == :call && new(exp).refute_raise? end
refute_raises?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 43 def refute_raises?(exp) exp.sexp_type == :call && new(exp).refute_raises? end
Public Instance Methods
argument_types()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 56 def argument_types arguments.map(&:sexp_type) end
arguments()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 52 def arguments @exp[3..-1] || [] end
assert_difference?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 60 def assert_difference? return false unless method_name == :assert_difference [[:str], %i[str lit]].include?(argument_types) end
assert_no_difference?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 65 def assert_no_difference? method_name == :assert_no_difference && arguments.length == 1 && arguments[0].sexp_type == :str end
assert_nothing_raised?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 71 def assert_nothing_raised? method_name == :assert_nothing_raised && arguments.empty? end
assert_raise?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 75 def assert_raise? method_name == :assert_raise && raise_error_args? end
assert_raises?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 79 def assert_raises? method_name == :assert_raises && raise_error_args? end
calls_in_receiver_chain()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 91 def calls_in_receiver_chain receiver_chain.each_with_object([]) do |e, a| next unless sexp_type?(:call, e) a << self.class.new(e) end end
find_call_in_receiver_chain(method_names)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 98 def find_call_in_receiver_chain(method_names) name_array = [method_names].flatten calls_in_receiver_chain.find { |i| name_array.include?(i.method_name) } end
method_name()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 105 def method_name @exp[2] end
num_arguments()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 109 def num_arguments arguments.length end
one_string_argument?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 113 def one_string_argument? arguments.length == 1 && string?(arguments[0]) end
question_mark_method?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 173 def question_mark_method? method_name.to_s.end_with?('?') end
raise_error_args?()
click to toggle source
Returns true if arguments can be processed into RSpec's `raise_error` matcher. When the last argument is a string, it represents the assertion failure message, which will be discarded later.
# File lib/minitest_to_rspec/input/model/call.rb, line 120 def raise_error_args? arg_types = arguments.map(&:sexp_type) [[], [:str], [:const], %i[const str], [:colon2]].include?(arg_types) end
receiver()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 125 def receiver @exp[1] end
receiver_chain()
click to toggle source
Consider the following chain of method calls:
@a.b.c
whose S-expression is
s(:call, s(:call, s(:call, nil, :a), :b), :c)
the “receiver chain” is
[ s(:call, s(:call, nil, :a), :b), s(:call, nil, :a), nil ]
The order of the returned array matches the order in which messages are received, i.e. the order of execution.
Note that the final receiver `nil` is included. This `nil` represents the implicit receiver, e.g. `self` or `main`.
# File lib/minitest_to_rspec/input/model/call.rb, line 151 def receiver_chain receivers = [] ptr = @exp while sexp_type?(:call, ptr) receivers << ptr[1] ptr = ptr[1] end receivers end
receiver_chain_include?(method_name)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 161 def receiver_chain_include?(method_name) receiver_chain.compact.any? { |r| self.class.method_name?(r, method_name) } end
refute_raise?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 83 def refute_raise? method_name == :refute_raise && raise_error_args? end
refute_raises?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 87 def refute_raises? method_name == :refute_raises && raise_error_args? end
require_test_helper?()
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 167 def require_test_helper? method_name == :require && one_string_argument? && arguments[0][1] == 'test_helper' end
Private Instance Methods
string?(exp)
click to toggle source
# File lib/minitest_to_rspec/input/model/call.rb, line 179 def string?(exp) exp.sexp_type == :str end