Class: Transpec::Context

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/transpec/context.rb

Constant Summary collapse

SCOPE_TYPES =
[:module, :class, :sclass, :def, :defs, :block].freeze
EXAMPLE_GROUP_METHOD_NAMES =
[
  :describe, :context,
  :shared_examples, :shared_context, :share_examples_for, :shared_examples_for
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

const_name, here_document?, in_parentheses?, indentation_of_line, proc_literal?

Constructor Details

#initialize(nodes) ⇒ Context

Returns a new instance of Context.

Parameters:

  • nodes (Array)

    An array containing from root node to the target node.



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

def initialize(nodes)
  @nodes = nodes
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



16
17
18
# File 'lib/transpec/context.rb', line 16

def nodes
  @nodes
end

Instance Method Details

#in_example_group?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/transpec/context.rb', line 30

def in_example_group?
  return @in_example_group if instance_variable_defined?(:@in_example_group)
  @in_example_group = in_method_or_block_in_example_group?   ||
                      in_method_or_block_in_rspec_configure? ||
                      in_method_in_module?                   ||
                      in_method_in_top_level?
end

#scopesObject



23
24
25
26
27
28
# File 'lib/transpec/context.rb', line 23

def scopes
  @scopes ||= begin
    scopes = @nodes.map { |node| scope_type(node) }
    scopes.compact
  end
end