Class: Transpec::Context

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

Defined Under Namespace

Modules: ArrayExtension

Constant Summary collapse

SCOPE_TYPES =
[:module, :class, :sclass, :def, :defs, :block].freeze
EXAMPLE_GROUP_METHODS =
[
  :describe, :context,
  :shared_examples, :shared_context, :share_examples_for, :shared_examples_for
].freeze
EXAMPLE_METHODS =
[
  :example, :it, :specify,
  :focus, :focused, :fit,
  :pending, :xexample, :xit, :xspecify
].freeze
HOOK_METHODS =
[:before, :after, :around].freeze
HELPER_METHODS =
[:subject, :subject!, :let, :let!]
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

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.



53
54
55
# File 'lib/transpec/context.rb', line 53

def initialize(nodes)
  @nodes = nodes
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



50
51
52
# File 'lib/transpec/context.rb', line 50

def nodes
  @nodes
end

Instance Method Details

#non_monkey_patch_expectation_available?Boolean Also known as: expect_to_matcher_available?

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/transpec/context.rb', line 65

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)


72
73
74
75
# File 'lib/transpec/context.rb', line 72

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



57
58
59
60
61
62
63
# File 'lib/transpec/context.rb', line 57

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