Class: Transpec::Syntax::ShouldReceive

Inherits:
Transpec::Syntax show all
Includes:
Mixin::AllowNoMessage, Mixin::AnyInstance, Mixin::Expectizable, Mixin::MonkeyPatch, Mixin::Send
Defined in:
lib/transpec/syntax/should_receive.rb

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

#arg_node, #arg_nodes, #arg_range, #args_range, included, #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::MonkeyPatch

#check_syntax_availability, #register_request_of_syntax_availability_inspection, #subject_node, #subject_range

Methods included from Mixin::Expectizable

#wrap_subject_in_expect!

Methods included from Mixin::AllowNoMessage

#allow_no_message?, #remove_allowance_for_no_message!

Methods included from Mixin::AnyInstance

#any_instance?, #any_instance_target_class_source, #any_instance_target_node, included

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)


18
19
20
# File 'lib/transpec/syntax/should_receive.rb', line 18

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

Instance Method Details

#allow_to_receive_available?Boolean

Returns:

  • (Boolean)


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

def allow_to_receive_available?
  check_syntax_availability(__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(selector_range, "##{method_name}", '#allow')
  end

  convert_to_syntax!('allow', negative_form)
  remove_allowance_for_no_message!

  register_record(:allow, negative_form)
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?
  check_syntax_availability(__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(selector_range, "##{method_name}", '#expect')
  end

  convert_to_syntax!('expect', negative_form)
  register_record(:expect, 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

#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_allowance_for_no_message!

  register_record(:stub)
end