Class: Transpec::Syntax::Should

Inherits:
Transpec::Syntax show all
Includes:
Expectizable, Util
Defined in:
lib/transpec/syntax/should.rb

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#ancestor_nodes, #node, #report, #source_rewriter

Instance Method Summary collapse

Methods included from Expectizable

#wrap_subject_in_expect!

Methods included from SendNodeSyntax

#arg_node, #arg_nodes, #arg_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 Util

const_name, here_document?, in_parentheses?, indentation_of_line, proc_literal?

Methods inherited from Transpec::Syntax

all, #context, #expression_range, inherited, #initialize, #parent_node, snake_case_name, target_node?

Constructor Details

This class inherits a constructor from Transpec::Syntax

Instance Method Details

#expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true) ⇒ Object



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

def expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true)
  unless context.expect_to_matcher_available?
    fail InvalidContextError.new(selector_range, "##{method_name}", '#expect')
  end

  if proc_literal?(subject_node)
    replace_proc_selector_with_expect!
  else
    wrap_subject_in_expect!
  end

  replace(should_range, positive? ? 'to' : negative_form)

  register_record(negative_form)

  matcher.correct_operator!(parenthesize_matcher_arg)
end

#matcherObject



35
36
37
# File 'lib/transpec/syntax/should.rb', line 35

def matcher
  @matcher ||= Matcher.new(matcher_node, @source_rewriter, @report)
end

#matcher_nodeObject



39
40
41
# File 'lib/transpec/syntax/should.rb', line 39

def matcher_node
  arg_node || parent_node
end

#positive?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/transpec/syntax/should.rb', line 13

def positive?
  method_name == :should
end