Class: Transpec::Syntax::ShouldReceive

Inherits:
Transpec::Syntax show all
Includes:
Mixin::Expectizable, Mixin::MessagingHost, Mixin::MonkeyPatchAnyInstance, Util
Defined in:
lib/transpec/syntax/should_receive.rb

Defined Under Namespace

Classes: AllowRecord, ExpectBaseRecord, ExpectRecord, StubRecord

Constant Summary

Constants included from Util

Util::LITERAL_TYPES, Util::WHITESPACES

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#node, #report, #runtime_data, #source_rewriter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Expectizable

#wrap_subject_in_expect!

Methods included from Mixin::MonkeyPatchAnyInstance

#any_instance?

Methods included from Mixin::MonkeyPatch

#check_syntax_availability, #register_request_of_syntax_availability_inspection, #subject_node, #subject_range

Methods included from Mixin::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 Mixin::NoMessageAllowance

#allow_no_message?, #any_number_of_times?, #at_least_zero?, #remove_no_message_allowance!

Methods included from Mixin::UselessAndReturn

#and_return?, #and_return_node, #and_return_with_block?, #useless_and_return?

Methods included from Util

beginning_of_line_range, block_node_taken_by_method, const_name, contain_here_document?, each_backward_chained_node, each_forward_chained_node, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, first_block_arg_name, here_document?, in_explicit_parentheses?, indentation_of_line, literal?, proc_literal?

Methods inherited from Transpec::Syntax

conversion_target_node?, #expression_range, #initialize, #parent_node, snake_case_name, standalone?, #static_context_inspector, target_node?

Methods included from Collection

#all_syntaxes, #inherited, #require_all, #standalone_syntaxes

Methods included from DynamicAnalysis

#register_request_for_dynamic_analysis

Constructor Details

This class inherits a constructor from Transpec::Syntax

Class Method Details

.target_method?(receiver_node, method_name) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/transpec/syntax/should_receive.rb', line 16

def self.target_method?(receiver_node, method_name)
  !receiver_node.nil? && [:should_receive, :should_not_receive].include?(method_name)
end

Instance Method Details

#add_receiver_arg_to_any_instance_implementation_block!Object



81
82
83
# File 'lib/transpec/syntax/should_receive.rb', line 81

def add_receiver_arg_to_any_instance_implementation_block!
  super && register_record(MonkeyPatchAnyInstanceBlockRecord)
end

#allow_to_receive_available?Boolean

Returns:

  • (Boolean)


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

def allow_to_receive_available?
  check_syntax_availability(__method__)
end

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



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/transpec/syntax/should_receive.rb', line 55

def allowize_useless_expectation!(negative_form = 'not_to')
  return unless useless_expectation?

  unless allow_to_receive_available?
    fail ContextError.new(selector_range, "##{method_name}", '#allow')
  end

  convert_to_syntax!('allow', negative_form)
  remove_no_message_allowance!

  register_record(AllowRecord, negative_form)
end

#expect_to_receive_available?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/transpec/syntax/should_receive.rb', line 34

def expect_to_receive_available?
  check_syntax_availability(__method__)
end

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



46
47
48
49
50
51
52
53
# File 'lib/transpec/syntax/should_receive.rb', line 46

def expectize!(negative_form = 'not_to')
  unless expect_to_receive_available?
    fail ContextError.new(selector_range, "##{method_name}", '#expect')
  end

  convert_to_syntax!('expect', negative_form)
  register_record(ExpectRecord, negative_form)
end

#positive?Boolean

Returns:

  • (Boolean)


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

def positive?
  method_name == :should_receive
end

#remove_useless_and_return!Object



77
78
79
# File 'lib/transpec/syntax/should_receive.rb', line 77

def remove_useless_and_return!
  super && register_record(MonkeyPatchUselessAndReturnRecord)
end

#stubize_useless_expectation!Object



68
69
70
71
72
73
74
75
# File 'lib/transpec/syntax/should_receive.rb', line 68

def stubize_useless_expectation!
  return unless useless_expectation?

  replace(selector_range, 'stub')
  remove_no_message_allowance!

  register_record(StubRecord)
end