Module: Transpec::Syntax::Mixin::Send::ClassMethods

Defined in:
lib/transpec/syntax/mixin/send.rb

Instance Method Summary collapse

Instance Method Details

#check_target_node_dynamically(node, runtime_data) ⇒ Object



26
27
28
29
30
31
# File 'lib/transpec/syntax/mixin/send.rb', line 26

def check_target_node_dynamically(node, runtime_data)
  source_location = source_location(node, runtime_data)
  return true unless source_location
  file_path = source_location.first
  !file_path.match(%r{/gems/rspec\-[^/]+/lib/rspec/}).nil?
end

#check_target_node_statically(node) ⇒ Object



16
17
18
19
20
# File 'lib/transpec/syntax/mixin/send.rb', line 16

def check_target_node_statically(node)
  return false unless node && node.type == :send
  receiver_node, method_name, *_ = *node
  target_method?(receiver_node, method_name)
end

#source_location(node, runtime_data) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/transpec/syntax/mixin/send.rb', line 33

def source_location(node, runtime_data)
  return unless runtime_data
  receiver_node, method_name, *_ = *node
  target_node = receiver_node ? receiver_node : node
  return unless (node_data = runtime_data[target_node])
  return unless (eval_data = node_data[source_location_key(method_name)])
  eval_data.result
end

#source_location_key(method_name) ⇒ Object



42
43
44
# File 'lib/transpec/syntax/mixin/send.rb', line 42

def source_location_key(method_name)
  "#{method_name}_source_location".to_sym
end

#target_method?(receiver_node, method_name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/transpec/syntax/mixin/send.rb', line 22

def target_method?(receiver_node, method_name)
  fail NotImplementedError
end

#target_node?(node, runtime_data = nil) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/transpec/syntax/mixin/send.rb', line 12

def target_node?(node, runtime_data = nil)
  check_target_node_statically(node) && check_target_node_dynamically(node, runtime_data)
end