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

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

#register_syntax_availability_analysis_request, #subject_node, #subject_range, #syntax_available?

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::Send::TargetDetection

#conversion_target?

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, chainable_source, const_name, contain_here_document?, each_backward_chained_node, each_forward_chained_node, each_line_range, end_of_line_range, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, first_block_arg_name, here_document?, in_explicit_parentheses?, indentation_of_line, line_range, literal?, node_id, proc_literal?, range_from_arg

Methods inherited from Transpec::Syntax

#conversion_target?, #expression_range, #initialize, #parent_node, snake_case_name, standalone?, #static_context_inspector

Methods included from Collection

#all_syntaxes, #inherited, #require_all, #standalone_syntaxes

Methods included from DynamicAnalysis

#register_dynamic_analysis_request

Constructor Details

This class inherits a constructor from Transpec::Syntax

Instance Method Details

#add_receiver_arg_to_any_instance_implementation_block!Object



83
84
85
# File 'lib/transpec/syntax/should_receive.rb', line 83

def add_receiver_arg_to_any_instance_implementation_block!
  super && register_record(MonkeyPatchAnyInstanceBlockRecord)
end

#allow_to_receive_available?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/transpec/syntax/should_receive.rb', line 40

def allow_to_receive_available?
  syntax_available?(__method__)
end

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



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

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

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

  convert_to_syntax!('allow', negative_form)
  remove_no_message_allowance!

  register_record(AllowRecord, negative_form)
end

#dynamic_analysis_target?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/transpec/syntax/should_receive.rb', line 30

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

#expect_to_receive_available?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/transpec/syntax/should_receive.rb', line 36

def expect_to_receive_available?
  syntax_available?(__method__)
end

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



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

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

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

#positive?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/transpec/syntax/should_receive.rb', line 44

def positive?
  method_name == :should_receive
end

#remove_useless_and_return!Object



79
80
81
# File 'lib/transpec/syntax/should_receive.rb', line 79

def remove_useless_and_return!
  super && register_record(MonkeyPatchUselessAndReturnRecord)
end

#stubize_useless_expectation!Object



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

def stubize_useless_expectation!
  return unless useless_expectation?

  replace(selector_range, 'stub')
  remove_no_message_allowance!

  register_record(StubRecord)
end