Class: Transpec::Syntax::MethodStub
- Inherits:
-
Transpec::Syntax
- Object
- Transpec::Syntax
- Transpec::Syntax::MethodStub
- Includes:
- AbleToAllowNoMessage, AbleToTargetAnyInstance, Util
- Defined in:
- lib/transpec/syntax/method_stub.rb
Constant Summary collapse
- RECEIVER_CLASS_WHITELIST =
['Typhoeus']
Instance Attribute Summary
Attributes inherited from Transpec::Syntax
#ancestor_nodes, #in_example_group_context, #node, #source_rewriter
Instance Method Summary collapse
Methods included from AbleToAllowNoMessage
#allow_no_message?, #remove_allowance_for_no_message!
Methods included from AbleToTargetAnyInstance
#any_instance?, #class_node_of_any_instance
Methods included from SendNodeSyntax
#arg_node, #arg_range, #method_name, #parentheses_range, #receiver_node, #receiver_range, #selector_range
Methods included from Util
const_name, here_document?, in_parentheses?, indentation_of_line, proc_literal?
Methods inherited from Transpec::Syntax
all, #expression_range, inherited, #initialize, #parent_node, snake_case_name, target_node?
Constructor Details
This class inherits a constructor from Transpec::Syntax
Instance Method Details
#allowize! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/transpec/syntax/method_stub.rb', line 16 def allowize! # There's no way of unstubbing in #allow syntax. return unless [:stub, :stub!].include?(method_name) fail 'Already replaced deprecated method, cannot allowize.' if @replaced_deprecated_method unless in_example_group_context? fail NotInExampleGroupContextError.new(expression_range, "##{method_name}", '#allow') end if arg_node.type == :hash expressions = build_allow_expressions_from_hash_node(arg_node) replace(expression_range, expressions) else expression = build_allow_expression(arg_node) replace(expression_range, expression) end @allowized = true end |
#replace_deprecated_method! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/transpec/syntax/method_stub.rb', line 37 def replace_deprecated_method! replacement_method_name = case method_name when :stub! then 'stub' when :unstub! then 'unstub' end return unless replacement_method_name fail 'Already allowized, cannot replace deprecated method.' if @allowized replace(selector_range, replacement_method_name) @replaced_deprecated_method = true end |