Class: Transpec::Syntax::ShouldReceive

Inherits:
Transpec::Syntax show all
Includes:
AnyInstanceable, Expectizable
Defined in:
lib/transpec/syntax/should_receive.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 AnyInstanceable

#any_instance?, #class_node_of_any_instance

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

#correct_block_style!Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/transpec/syntax/should_receive.rb', line 32

def correct_block_style!
  return if broken_block_nodes.empty?

  broken_block_nodes.each do |block_node|
    map = block_node.loc
    next if map.begin.source == '{'
    replace(map.begin, '{')
    replace(map.end, '}')
  end
end

#expectize!(negative_form = 'not_to') ⇒ Object



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

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

  if any_instance?
    wrap_class_in_expect_any_instance_of!
  else
    wrap_subject_in_expect!
  end

  replace(selector_range, "#{positive? ? 'to' : negative_form} receive")

  correct_block_style!
end

#positive?Boolean

Returns:

  • (Boolean)


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

def positive?
  method_name == :should_receive
end