Class: Transpec::Syntax::Have::SourceBuilder

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/transpec/syntax/have/source_builder.rb

Constant Summary

Constants included from Util

Util::LITERAL_TYPES, Util::WHITESPACES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

beginning_of_line_range, block_node_taken_by_method, chainable_source, const_name, contain_here_document?, each_backward_chained_node, each_forward_chained_node, each_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?, proc_literal?, range_from_arg

Constructor Details

#initialize(have, size_source) ⇒ SourceBuilder

Returns a new instance of SourceBuilder.



13
14
15
16
# File 'lib/transpec/syntax/have/source_builder.rb', line 13

def initialize(have, size_source)
  @have = have
  @size_source = size_source
end

Instance Attribute Details

#haveObject (readonly)

Returns the value of attribute have.



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

def have
  @have
end

#size_sourceObject (readonly)

Returns the value of attribute size_source.



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

def size_source
  @size_source
end

Instance Method Details

#replacement_matcher_source(parenthesize_arg = true) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/transpec/syntax/have/source_builder.rb', line 40

def replacement_matcher_source(parenthesize_arg = true)
  case have.expectation.current_syntax_type
  when :should
    replacement_matcher_source_for_should
  when :expect
    replacement_matcher_source_for_expect(parenthesize_arg)
  end
end

#replacement_subject_source(base_subject) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/transpec/syntax/have/source_builder.rb', line 18

def replacement_subject_source(base_subject)
  source = case base_subject
           when String    then base_subject
           when AST::Node then base_subject_source(base_subject)
           else fail "Invalid base subject #{base_subject}"
           end

  if have.subject_is_owner_of_collection?
    if have.collection_accessor_is_private?
      source << ".send(#{have.collection_accessor.inspect}"
      if have.items_method_has_arguments?
        source << ", #{collection_accessor_args_body_source}"
      end
      source << ')'
    else
      source << ".#{have.collection_accessor}#{collection_accessor_args_parentheses_source}"
    end
  end

  source << ".#{have.query_method}"
end