Method: Transpec::Syntax::MethodStub#allowize!

Defined in:
lib/transpec/syntax/method_stub.rb

#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