Class: Transpec::Syntax::MethodStub

Constant Summary

Constants included from Util

Util::LITERAL_TYPES

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#node, #report, #runtime_data, #source_rewriter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Transpec::Syntax::Mixin::Send

#arg_node, #arg_nodes, #arg_range, included, #method_name, #parentheses_range, #range_after_arg, #range_in_between_receiver_and_selector, #range_in_between_selector_and_arg, #receiver_node, #receiver_range, #selector_range

Methods included from Transpec::Syntax::Mixin::MonkeyPatch

#check_syntax_availability, #register_request_of_syntax_availability_inspection, #subject_node, #subject_range

Methods included from Transpec::Syntax::Mixin::AllowNoMessage

#allow_no_message?, #remove_allowance_for_no_message!

Methods included from Transpec::Syntax::Mixin::AnyInstance

#any_instance?, #class_node_of_any_instance

Methods included from Util

const_name, contain_here_document?, here_document?, in_parentheses?, indentation_of_line, literal?, proc_literal?

Methods inherited from Transpec::Syntax

all_syntaxes, #expression_range, inherited, #initialize, #parent_node, register_request_for_dynamic_analysis, snake_case_name, standalone?, standalone_syntaxes, #static_context_inspector, target_node?

Constructor Details

This class inherits a constructor from Transpec::Syntax

Class Method Details

.target_method?(receiver_node, method_name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/transpec/syntax/method_stub.rb', line 16

def self.target_method?(receiver_node, method_name)
  !receiver_node.nil? && [:stub, :unstub, :stub!, :unstub!].include?(method_name)
end

Instance Method Details

#allow_to_receive_available?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/transpec/syntax/method_stub.rb', line 28

def allow_to_receive_available?
  check_syntax_availability(__method__)
end

#allowize!(receive_messages_available = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/transpec/syntax/method_stub.rb', line 32

def allowize!(receive_messages_available = false)
  # There's no way of unstubbing in #allow syntax.
  return unless [:stub, :stub!].include?(method_name)

  unless allow_to_receive_available?
    fail InvalidContextError.new(selector_range, "##{method_name}", '#allow')
  end

  source, type = if arg_node.type == :hash
                   if receive_messages_available
                     [build_allow_to_receive_messages_expression, :allow_to_receive_messages]
                   else
                     [build_allow_expressions_from_hash_node(arg_node), :allow_to_receive]
                   end
                 else
                   [build_allow_expression(arg_node), :allow_to_receive]
                 end

  replace(expression_range, source)

  register_record(type)
end

#convert_deprecated_method!Object



55
56
57
58
59
60
61
# File 'lib/transpec/syntax/method_stub.rb', line 55

def convert_deprecated_method!
  return unless replacement_method_for_deprecated_method

  replace(selector_range, replacement_method_for_deprecated_method)

  register_record(:deprecated)
end

#register_request_for_dynamic_analysis(rewriter) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/transpec/syntax/method_stub.rb', line 20

def register_request_for_dynamic_analysis(rewriter)
  register_request_of_syntax_availability_inspection(
    rewriter,
    :allow_to_receive_available?,
    [:allow, :receive]
  )
end