Module: Transpec::Syntax::Mixin::ExpectBase

Extended by:
ActiveSupport::Concern
Includes:
MatcherOwner, Send
Included in:
Allow, Expect
Defined in:
lib/transpec/syntax/mixin/expect_base.rb

Instance Method Summary collapse

Methods included from Send

#arg_node, #arg_nodes, #arg_range, #args_range, #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 Send::TargetDetection

#conversion_target?

Methods included from MatcherOwner

#dependent_syntaxes

Instance Method Details

#block_nodeObject



62
63
64
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 62

def block_node
  Util.block_node_taken_by_method(to_node)
end

#current_syntax_typeObject



24
25
26
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 24

def current_syntax_type
  :expect
end

#dynamic_analysis_target?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 20

def dynamic_analysis_target?
  super && receiver_node.nil? && matcher_node
end

#matcher_nodeObject



54
55
56
57
58
59
60
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 54

def matcher_node
  return nil unless to_node
  to_arg_node = to_node.children[2]
  return nil unless to_arg_node
  Util.each_forward_chained_node(to_arg_node, :include_origin)
    .select(&:send_type?).to_a.last
end

#method_name_for_instanceObject



28
29
30
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 28

def method_name_for_instance
  fail NotImplementedError
end

#positive?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 32

def positive?
  to_method_name = to_node.children[1]
  # `expect { do_something }.should raise_error` is possible in RSpec 2.
  [:to, :should].include?(to_method_name)
end

#subject_nodeObject



38
39
40
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 38

def subject_node
  arg_node || parent_node
end

#subject_rangeObject



66
67
68
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 66

def subject_range
  subject_node.loc.expression
end

#to_nodeObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/transpec/syntax/mixin/expect_base.rb', line 42

def to_node
  return nil unless parent_node

  if parent_node.block_type? && parent_node.children.first.equal?(node)
    parent_node.parent
  elsif parent_node.send_type? && parent_node.children.first.equal?(node)
    parent_node
  else
    nil
  end
end