Class: Transpec::StaticContextInspector
- Inherits:
-
Object
- Object
- Transpec::StaticContextInspector
- 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
- EXAMPLE_CONTEXTS =
[ [: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
- EXAMPLE_GROUP_CONTEXTS =
[ [:example_group, :all_before_after], [:example_group, :around], [:rspec_configure, :all_before_after], [:rspec_configure, :around] ].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
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#rspec_version ⇒ Object
readonly
Returns the value of attribute rspec_version.
Instance Method Summary collapse
-
#initialize(node, rspec_version) ⇒ StaticContextInspector
constructor
A new instance of StaticContextInspector.
- #non_monkey_patch_expectation_available? ⇒ Boolean (also: #expect_available?)
- #non_monkey_patch_mock_available? ⇒ Boolean (also: #expect_to_receive_available?, #allow_to_receive_available?)
- #scopes ⇒ Object
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(node, rspec_version) ⇒ StaticContextInspector
Returns a new instance of StaticContextInspector.
32 33 34 35 |
# File 'lib/transpec/static_context_inspector.rb', line 32 def initialize(node, rspec_version) @node = node @rspec_version = rspec_version end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
30 31 32 |
# File 'lib/transpec/static_context_inspector.rb', line 30 def node @node end |
#rspec_version ⇒ Object (readonly)
Returns the value of attribute rspec_version.
30 31 32 |
# File 'lib/transpec/static_context_inspector.rb', line 30 def rspec_version @rspec_version end |
Instance Method Details
#non_monkey_patch_expectation_available? ⇒ Boolean Also known as: expect_available?
45 46 47 48 49 |
# File 'lib/transpec/static_context_inspector.rb', line 45 def non_monkey_patch_expectation_available? return @expectation_available if instance_variable_defined?(:@expectation_available) contexts = EXAMPLE_CONTEXTS + EXAMPLE_GROUP_CONTEXTS @expectation_available = match_context?(contexts) end |
#non_monkey_patch_mock_available? ⇒ Boolean Also known as: expect_to_receive_available?, allow_to_receive_available?
53 54 55 56 57 58 |
# File 'lib/transpec/static_context_inspector.rb', line 53 def non_monkey_patch_mock_available? return @mock_available if instance_variable_defined?(:@mock_available) contexts = EXAMPLE_CONTEXTS contexts += EXAMPLE_GROUP_CONTEXTS if rspec_version.rspec_3? @mock_available = match_context?(contexts) end |
#scopes ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/transpec/static_context_inspector.rb', line 37 def scopes @scopes ||= begin scopes = valid_ancestor_nodes.reverse_each.map { |node| scope_type(node) } scopes.compact! scopes.extend(ArrayExtension) end end |