Class: Transpec::Syntax::Should

Inherits:
Transpec::Syntax show all
Includes:
Mixin::Expectizable, Mixin::MonkeyPatch, Mixin::ShouldBase, Util
Defined in:
lib/transpec/syntax/should.rb

Constant Summary

Constants included from Util

Util::LITERAL_TYPES, Util::WHITESPACES

Instance Attribute Summary collapse

Attributes inherited from Transpec::Syntax

#node, #report, #runtime_data, #source_rewriter

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ShouldBase

#matcher_node, #positive?, #should_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::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 Util

beginning_of_line_range, block_node_taken_by_method, 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_node?, #expression_range, #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

#initialize(node, source_rewriter = nil, runtime_data = nil, report = nil) ⇒ Should

Returns a new instance of Should.



20
21
22
23
# File 'lib/transpec/syntax/should.rb', line 20

def initialize(node, source_rewriter = nil, runtime_data = nil, report = nil)
  super
  @current_syntax_type = :should
end

Instance Attribute Details

#current_syntax_typeObject (readonly)

Returns the value of attribute current_syntax_type.



14
15
16
# File 'lib/transpec/syntax/should.rb', line 14

def current_syntax_type
  @current_syntax_type
end

Class Method Details

.target_method?(receiver_node, method_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#expect_available?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/transpec/syntax/should.rb', line 33

def expect_available?
  check_syntax_availability(__method__)
end

#expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/transpec/syntax/should.rb', line 37

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

  if proc_literal?(subject_node)
    replace(range_of_subject_method_taking_block, 'expect')
  else
    wrap_subject_in_expect!
  end

  replace(should_range, positive? ? 'to' : negative_form)

  @current_syntax_type = :expect
  register_record(negative_form)

  operator_matcher.convert_operator!(parenthesize_matcher_arg) if operator_matcher
end