Class: Transpec::Syntax::RaiseError

Inherits:
Transpec::Syntax show all
Includes:
SendNodeSyntax
Defined in:
lib/transpec/syntax/raise_error.rb

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#ancestor_nodes, #node, #report, #source_rewriter

Instance Method Summary collapse

Methods included from SendNodeSyntax

#arg_node, #arg_nodes, #arg_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 inherited from Transpec::Syntax

all, #context, #expression_range, inherited, #initialize, #parent_node, snake_case_name, target_node?

Constructor Details

This class inherits a constructor from Transpec::Syntax

Instance Method Details

#positive?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
# File 'lib/transpec/syntax/raise_error.rb', line 22

def positive?
  ancestor_nodes.reverse_each do |ancestor_node|
    next unless ancestor_node.type == :send
    expectation_method_name = ancestor_node.children[1]
    return [:should, :to].include?(expectation_method_name)
  end

  false
end

#remove_error_specification_with_negative_expectation!Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/transpec/syntax/raise_error.rb', line 11

def remove_error_specification_with_negative_expectation!
  return if positive?

  _receiver_node, _method_name, *arg_nodes = *node
  return if arg_nodes.empty?

  remove(parentheses_range)

  register_record
end