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, #in_example_group_context, #node, #source_rewriter

Instance Method Summary collapse

Methods included from Expectizable

#wrap_subject_in_expect!

Methods included from SendNodeSyntax

#arg_node, #arg_range, #method_name, #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, #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
# File 'lib/transpec/syntax/should.rb', line 17

def expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true)
  unless in_example_group_context?
    fail NotInExampleGroupContextError.new(expression_range, "##{method_name}", '#expect')
  end

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

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

  matcher.correct_operator!(parenthesize_matcher_arg)
end

#matcherObject



33
34
35
# File 'lib/transpec/syntax/should.rb', line 33

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

#matcher_nodeObject



37
38
39
# File 'lib/transpec/syntax/should.rb', line 37

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