Class: Transpec::Syntax::MethodStub
- Inherits:
-
Transpec::Syntax
- Object
- Transpec::Syntax
- Transpec::Syntax::MethodStub
- Includes:
- Transpec::Syntax::Mixin::AllowNoMessage, Transpec::Syntax::Mixin::AnyInstance, Transpec::Syntax::Mixin::MonkeyPatch, Transpec::Syntax::Mixin::Send, Util
- Defined in:
- lib/transpec/syntax/method_stub.rb
Constant Summary collapse
- CLASSES_DEFINING_OWN_STUB_METHOD =
rubocop:disable LineLength
[ 'Typhoeus', # https://github.com/typhoeus/typhoeus/blob/6a59c62/lib/typhoeus.rb#L66-L85 'Excon', # https://github.com/geemus/excon/blob/6af4f9c/lib/excon.rb#L143-L178 'Factory' # https://github.com/thoughtbot/factory_girl/blob/v3.6.2/lib/factory_girl/syntax/vintage.rb#L112 ]
Constants included from Util
Util::LITERAL_TYPES, Util::WHITESPACES
Instance Attribute Summary
Attributes inherited from Transpec::Syntax
#node, #report, #runtime_data, #source_rewriter
Class Method Summary collapse
- .conversion_target_node?(node, runtime_data = nil) ⇒ Boolean
-
.dynamic_analysis_target_node?(node) ⇒ Boolean
rubocop:enable LineLength.
- .target_method?(receiver_node, method_name) ⇒ Boolean
Instance Method Summary collapse
- #allow_to_receive_available? ⇒ Boolean
- #allowize!(rspec_version) ⇒ Object
- #convert_deprecated_method! ⇒ Object
Methods included from Transpec::Syntax::Mixin::Send
#arg_node, #arg_nodes, #arg_range, #args_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?, #any_instance_target_class_source, #any_instance_target_node, included
Methods included from Util
const_name, contain_here_document?, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, here_document?, in_explicit_parentheses?, indentation_of_line, literal?, proc_literal?, taking_block?
Methods inherited from Transpec::Syntax
#expression_range, #initialize, #parent_node, snake_case_name, standalone?, #static_context_inspector, target_node?
Methods included from Collection
#all_syntaxes, #inherited, #require_all, #standalone_syntaxes
Methods included from DynamicAnalysis
#register_request_for_dynamic_analysis
Constructor Details
This class inherits a constructor from Transpec::Syntax
Class Method Details
.conversion_target_node?(node, runtime_data = nil) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/transpec/syntax/method_stub.rb', line 28 def self.conversion_target_node?(node, runtime_data = nil) return false unless check_target_node_statically(node) # Check if the method is RSpec's one or not. if source_location(node, runtime_data) # If we have a source location runtime data, check with it. check_target_node_dynamically(node, runtime_data) else # Otherwise check with a static whitelist. receiver_node = node.children.first const_name = Util.const_name(receiver_node) !CLASSES_DEFINING_OWN_STUB_METHOD.include?(const_name) end end |
.dynamic_analysis_target_node?(node) ⇒ Boolean
rubocop:enable LineLength
24 25 26 |
# File 'lib/transpec/syntax/method_stub.rb', line 24 def self.dynamic_analysis_target_node?(node) target_node?(node) end |
.target_method?(receiver_node, method_name) ⇒ Boolean
43 44 45 |
# File 'lib/transpec/syntax/method_stub.rb', line 43 def self.target_method?(receiver_node, method_name) !receiver_node.nil? && [:stub, :stub!, :stub_chain, :unstub, :unstub!].include?(method_name) end |
Instance Method Details
#allow_to_receive_available? ⇒ Boolean
55 56 57 |
# File 'lib/transpec/syntax/method_stub.rb', line 55 def allow_to_receive_available? check_syntax_availability(__method__) end |
#allowize!(rspec_version) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/transpec/syntax/method_stub.rb', line 59 def allowize!(rspec_version) # There's no way of unstubbing in #allow syntax. return unless [:stub, :stub!, :stub_chain].include?(method_name) return if method_name == :stub_chain && !rspec_version. unless allow_to_receive_available? fail ContextError.new(selector_range, "##{method_name}", '#allow') end source, type = replacement_source_and_conversion_type(rspec_version) return unless source replace(expression_range, source) register_record(type) end |
#convert_deprecated_method! ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/transpec/syntax/method_stub.rb', line 76 def convert_deprecated_method! return unless replacement_method_for_deprecated_method replace(selector_range, replacement_method_for_deprecated_method) register_record(:deprecated) end |