Class: Transpec::StaticContextInspector

Inherits:
Object
  • Object
show all
Includes:
RSpecDSL, Util
Defined in:
lib/transpec/static_context_inspector.rb

Defined Under Namespace

Modules: ArrayExtension

Constant Summary collapse

SCOPE_TYPES =
[:module, :class, :sclass, :def, :defs, :block].freeze
TWISTED_SCOPE_TYPES =
(SCOPE_TYPES - [:def, :defs]).freeze
NON_MONKEY_PATCH_EXPECTATION_AVAILABLE_CONTEXT =
[
  [:example_group, :example],
  [:example_group, :each_before_after],
  [:example_group, :all_before_after],
  [:example_group, :around],
  [:example_group, :helper],
  [:example_group, :def],
  [:rspec_configure, :each_before_after],
  [:rspec_configure, :all_before_after],
  [:rspec_configure, :around],
  [:rspec_configure, :def],
  [:module, :def]
].freeze
NON_MONKEY_PATCH_MOCK_AVAILABLE_CONTEXT =
[
  [:example_group, :example],
  [:example_group, :each_before_after],
  [:example_group, :helper],
  [:example_group, :def],
  [:rspec_configure, :each_before_after],
  [:rspec_configure, :def],
  [:module, :def]
].freeze

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 collapse

Instance Method Summary collapse

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?

Constructor Details

#initialize(node) ⇒ StaticContextInspector

Returns a new instance of StaticContextInspector.



39
40
41
# File 'lib/transpec/static_context_inspector.rb', line 39

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



37
38
39
# File 'lib/transpec/static_context_inspector.rb', line 37

def node
  @node
end

Instance Method Details

#inside_of_example_group?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/transpec/static_context_inspector.rb', line 51

def inside_of_example_group?
  scopes.include?(:example_group)
end

#non_monkey_patch_expectation_available?Boolean Also known as: expect_available?

Returns:

  • (Boolean)


55
56
57
58
# File 'lib/transpec/static_context_inspector.rb', line 55

def non_monkey_patch_expectation_available?
  return @expectation_available if instance_variable_defined?(:@expectation_available)
  @expectation_available = match_scopes(NON_MONKEY_PATCH_EXPECTATION_AVAILABLE_CONTEXT)
end

#non_monkey_patch_mock_available?Boolean Also known as: expect_to_receive_available?, allow_to_receive_available?

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/transpec/static_context_inspector.rb', line 62

def non_monkey_patch_mock_available?
  return @mock_available if instance_variable_defined?(:@mock_available)
  @mock_available = match_scopes(NON_MONKEY_PATCH_MOCK_AVAILABLE_CONTEXT)
end

#scopesObject



43
44
45
46
47
48
49
# File 'lib/transpec/static_context_inspector.rb', line 43

def scopes
  @scopes ||= begin
    scopes = valid_ancestor_nodes.reverse_each.map { |node| scope_type(node) }
    scopes.compact!
    scopes.extend(ArrayExtension)
  end
end