Class: Transpec::Syntax::MethodStub

Inherits:
Transpec::Syntax show all
Includes:
AnyInstanceable, AnyNumberOfTimesable, Util
Defined in:
lib/transpec/syntax/method_stub.rb

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#ancestor_nodes, #in_example_group_context, #node, #source_rewriter

Instance Method Summary collapse

Methods included from AnyInstanceable

#any_instance?, #class_node_of_any_instance

Methods included from SendNodeSyntax

#arg_node, #arg_range, #method_name, #receiver_node, #receiver_range, #selector_range

Methods included from AnyNumberOfTimesable

#any_number_of_times?, #remove_any_number_of_times!

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/transpec/syntax/method_stub.rb', line 14

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/transpec/syntax/method_stub.rb', line 35

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