Class: Transpec::Syntax::Should

Inherits:
Transpec::Syntax show all
Includes:
Mixin::Expectizable, Mixin::HaveMatcherOwner, Mixin::MonkeyPatch, Mixin::Send, 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

included, #matcher_node, #operator_matcher, #positive?, #should_range

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

#have_matcher, included

Methods included from Util

const_name, contain_here_document?, expand_range_to_adjacent_whitespaces, find_consecutive_whitespace_position, here_document?, in_explicit_parentheses?, indentation_of_line, literal?, proc_literal?, taking_block?

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.



23
24
25
26
# File 'lib/transpec/syntax/should.rb', line 23

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.



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

def current_syntax_type
  @current_syntax_type
end

Class Method Details

.target_method?(receiver_node, method_name) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


36
37
38
# File 'lib/transpec/syntax/should.rb', line 36

def expect_available?
  check_syntax_availability(__method__)
end

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



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

def expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true)
  fail ContextError.new(selector_range, "##{method_name}", '#expect') 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