Class: Transpec::Syntax::MethodStub
Defined Under Namespace
Classes: AllowRecord, DeprecatedMethodRecord, NoMessageAllowanceRecord
Constant Summary
collapse
- CLASSES_DEFINING_OWN_STUB_METHOD =
rubocop:disable LineLength
[
'Typhoeus',
'Excon',
'Factory'
]
Constants included
from Util
Util::LITERAL_TYPES, Util::WHITESPACES
Instance Method Summary
collapse
#any_instance?
#register_syntax_availability_analysis_request, #subject_node, #subject_range, #syntax_available?
#arg_node, #arg_nodes, #arg_range, #args_range, #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
#need_to_add_receiver_arg_to_any_instance_implementation_block?
#allow_no_message?, #any_number_of_times?, #at_least_zero?
#and_return?, #and_return_node, #and_return_with_block?, #useless_and_return?
Methods included from Util
beginning_of_line_range, block_node_taken_by_method, chainable_source, const_name, contain_here_document?, each_backward_chained_node, each_forward_chained_node, each_line_range, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, first_block_arg_name, here_document?, in_explicit_parentheses?, indentation_of_line, line_range, literal?, proc_literal?, range_from_arg
Instance Method Details
#add_receiver_arg_to_any_instance_implementation_block! ⇒ Object
95
96
97
|
# File 'lib/transpec/syntax/method_stub.rb', line 95
def add_receiver_arg_to_any_instance_implementation_block!
super && add_record(:any_instance_block)
end
|
#allow_to_receive_available? ⇒ Boolean
50
51
52
|
# File 'lib/transpec/syntax/method_stub.rb', line 50
def allow_to_receive_available?
syntax_available?(__method__)
end
|
#allowize!(rspec_version) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/transpec/syntax/method_stub.rb', line 62
def allowize!(rspec_version)
return if method_name == :stub_chain && !rspec_version.receive_message_chain_available?
unless allow_to_receive_available?
fail ContextError.new("##{method_name}", '#allow', selector_range)
end
source, type = replacement_source_and_conversion_type(rspec_version)
return unless source
replace(expression_range, source)
add_record(type)
end
|
#conversion_target? ⇒ Boolean
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/transpec/syntax/method_stub.rb', line 36
def conversion_target?
return false unless dynamic_analysis_target?
if runtime_data.run?(send_analysis_target_node)
defined_by_rspec?
else
const_name = const_name(receiver_node)
!CLASSES_DEFINING_OWN_STUB_METHOD.include?(const_name)
end
end
|
#convert_deprecated_method! ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/transpec/syntax/method_stub.rb', line 77
def convert_deprecated_method!
return unless replacement_method_for_deprecated_method
replace(selector_range, replacement_method_for_deprecated_method)
add_record(:deprecated)
end
|
#dynamic_analysis_target? ⇒ Boolean
30
31
32
33
34
|
# File 'lib/transpec/syntax/method_stub.rb', line 30
def dynamic_analysis_target?
super &&
receiver_node &&
[:stub, :stub!, :stub_chain, :unstub, :unstub!].include?(method_name)
end
|
#hash_arg? ⇒ Boolean
54
55
56
|
# File 'lib/transpec/syntax/method_stub.rb', line 54
def hash_arg?
arg_node.hash_type?
end
|
#remove_no_message_allowance! ⇒ Object
85
86
87
88
89
|
# File 'lib/transpec/syntax/method_stub.rb', line 85
def remove_no_message_allowance!
return unless allow_no_message?
super
add_record(:no_message_allowance)
end
|
#remove_useless_and_return! ⇒ Object
91
92
93
|
# File 'lib/transpec/syntax/method_stub.rb', line 91
def remove_useless_and_return!
super && add_record(:useless_and_return)
end
|
#unstub? ⇒ Boolean
58
59
60
|
# File 'lib/transpec/syntax/method_stub.rb', line 58
def unstub?
[:unstub, :unstub!].include?(method_name)
end
|