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: AllowRecordBuilder, ExpectBaseRecordBuilder, ExpectRecordBuilder, StubRecordBuilder

Constant Summary

Constants included from Util

Util::LITERAL_TYPES, Util::WHITESPACES

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#node, #project, #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::AnyInstanceBlock

#need_to_add_receiver_arg_to_any_instance_implementation_block?

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, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, first_block_arg_name, here_document?, in_explicit_parentheses?, indentation_of_line, line_range, literal?, proc_literal?, range_from_arg

Methods inherited from Transpec::Syntax

#add_record, #conversion_target?, #dependent_syntaxes, #expression_range, #initialize, #inspect, #parent_node, #rspec_version, snake_case_name, standalone?, #static_context_inspector

Methods included from Collection

#all_syntaxes, #inherited, #mixins, #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



85
86
87
88
# File 'lib/transpec/syntax/should_receive.rb', line 85

def add_receiver_arg_to_any_instance_implementation_block!
  return unless super
  add_record(Mixin::AnyInstanceBlock::MonkeyPatchRecordBuilder.build(self))
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



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

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!

  add_record(AllowRecordBuilder.build(self, 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 &&
    [: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
56
# 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)

  add_record(ExpectRecordBuilder.build(self, 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



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

def remove_useless_and_return!
  return unless super
  add_record(Mixin::UselessAndReturn::MonkeyPatchRecordBuilder.build(self))
end

#stubize_useless_expectation!Object



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

def stubize_useless_expectation!
  return unless useless_expectation?

  replace(selector_range, 'stub')
  remove_no_message_allowance!

  add_record(StubRecordBuilder.build(self))
end