Class: Transpec::Syntax::ExampleGroup

Inherits:
Transpec::Syntax show all
Includes:
RSpecDSL, Mixin::ContextSensitive, Mixin::Metadata, Mixin::MonkeyPatch, Mixin::RSpecRails, Util
Defined in:
lib/transpec/syntax/example_group.rb

Defined Under Namespace

Classes: ExplicitTypeMetadataRecordBuilder, NonMonkeyPatchRecordBuilder

Constant Summary collapse

DIRECTORY_TO_TYPE_MAP =
{
  'controllers' => :controller,
  'helpers'     => :helper,
  'mailers'     => :mailer,
  'models'      => :model,
  'requests'    => :request,
  'integration' => :request,
  'api'         => :request,
  'routing'     => :routing,
  'views'       => :view,
  'features'    => :feature
}

Constants included from RSpecDSL

RSpecDSL::EXAMPLE_GROUP_METHODS, RSpecDSL::EXAMPLE_METHODS, RSpecDSL::HELPER_METHODS, RSpecDSL::HOOK_METHODS

Constants included from Util

Util::LITERAL_TYPES, Util::WHITESPACES

Instance Attribute Summary

Attributes inherited from Transpec::Syntax

#node, #project, #report, #runtime_data, #source_rewriter

Instance Method Summary collapse

Methods included from Mixin::ContextSensitive

#conversion_target?

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::Send::TargetDetection

#conversion_target?

Methods included from Mixin::Metadata

#metadata_key_nodes, #metadata_nodes

Methods included from Mixin::MonkeyPatch

#register_syntax_availability_analysis_request, #subject_node, #subject_range, #syntax_available?

Methods included from Mixin::RSpecRails

#rspec_rails?

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

Methods inherited from Transpec::Syntax

#add_record, #conversion_target?, #dependent_syntaxes, #expression_range, #initialize, #inspect, #parent_node, #rspec_version, snake_case_name, standalone?, #static_context_inspector

Methods included from Collection

#all_syntaxes, #inherited, #mixins, #require_all, #standalone_syntaxes

Methods included from DynamicAnalysis

#register_dynamic_analysis_request

Constructor Details

This class inherits a constructor from Transpec::Syntax

Instance Method Details

#add_explicit_type_metadata!Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/transpec/syntax/example_group.rb', line 45

def add_explicit_type_metadata!
  return unless rspec_rails?
  return unless method_name == :describe
  return if explicit_type_metadata?

  type = 
  return unless type

  code = ', '
  code << if  == :arrow
            ":type => #{type.inspect}"
          else
            "type: #{type.inspect}"
          end

  insert_after(, code)

  add_record(ExplicitTypeMetadataRecordBuilder.build(self))
end

#convert_to_non_monkey_patch!Object



39
40
41
42
43
# File 'lib/transpec/syntax/example_group.rb', line 39

def convert_to_non_monkey_patch!
  return if receiver_node
  insert_before(expression_range, 'RSpec.')
  add_record(NonMonkeyPatchRecordBuilder.build(self))
end

#dynamic_analysis_target?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/transpec/syntax/example_group.rb', line 29

def dynamic_analysis_target?
  return false unless super
  return false if receiver_node && const_name(receiver_node) != 'RSpec'
  EXAMPLE_GROUP_METHODS.include?(method_name)
end

#implicit_type_metadataObject



65
66
67
68
69
# File 'lib/transpec/syntax/example_group.rb', line 65

def 
  dirs = file_path.split('/')
  return nil unless dirs.first == 'spec'
  DIRECTORY_TO_TYPE_MAP[dirs[1]]
end

#should_be_in_example_group_context?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/transpec/syntax/example_group.rb', line 35

def should_be_in_example_group_context?
  false
end