Class: Transpec::Syntax::BeClose

Inherits:
Transpec::Syntax show all
Includes:
Mixin::Send
Defined in:
lib/transpec/syntax/be_close.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 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)


11
12
13
# File 'lib/transpec/syntax/be_close.rb', line 11

def self.target_method?(receiver_node, method_name)
  receiver_node.nil? && method_name == :be_close
end

Instance Method Details

#convert_to_be_within!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/transpec/syntax/be_close.rb', line 15

def convert_to_be_within!
  _receiver_node, _method_name, expected_node, delta_node = *node

  be_within_source = 'be_within('
  be_within_source << delta_node.loc.expression.source
  be_within_source << ').of('
  be_within_source << expected_node.loc.expression.source
  be_within_source << ')'

  replace(expression_range, be_within_source)

  register_record
end