Class: Solargraph::Rspec::SpecWalker::NodeTypes
- Inherits:
-
Object
- Object
- Solargraph::Rspec::SpecWalker::NodeTypes
- Defined in:
- lib/solargraph/rspec/spec_walker/node_types.rb
Class Method Summary collapse
- .a_block?(ast) ⇒ Boolean
- .a_constant?(ast) ⇒ Boolean
- .a_context_block?(block_ast) ⇒ Boolean
- .a_example_block?(block_ast, config) ⇒ Boolean
- .a_hook_block?(block_ast) ⇒ Boolean
- .a_let_block?(block_ast, config) ⇒ Boolean
- .a_subject_block?(block_ast) ⇒ Boolean
- .context_description_node(block_ast) ⇒ ::Parser::AST::Node?
- .let_method_name(block_ast) ⇒ String?
-
.method_with_block_name(block_ast) ⇒ String?
The name of the thing you are calling the block on.
Class Method Details
.a_block?(ast) ⇒ Boolean
9 10 11 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 9 def self.a_block?(ast) ast.is_a?(::Parser::AST::Node) && ast.type == :block end |
.a_constant?(ast) ⇒ Boolean
47 48 49 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 47 def self.a_constant?(ast) ast.type == :const end |
.a_context_block?(block_ast) ⇒ Boolean
15 16 17 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 15 def self.a_context_block?(block_ast) Solargraph::Rspec::CONTEXT_METHODS.include?(method_with_block_name(block_ast)) end |
.a_example_block?(block_ast, config) ⇒ Boolean
28 29 30 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 28 def self.a_example_block?(block_ast, config) config.example_methods.map(&:to_s).include?(method_with_block_name(block_ast)) end |
.a_hook_block?(block_ast) ⇒ Boolean
41 42 43 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 41 def self.a_hook_block?(block_ast) Solargraph::Rspec::HOOK_METHODS.include?(method_with_block_name(block_ast)) end |
.a_let_block?(block_ast, config) ⇒ Boolean
35 36 37 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 35 def self.a_let_block?(block_ast, config) config.let_methods.map(&:to_s).include?(method_with_block_name(block_ast)) end |
.a_subject_block?(block_ast) ⇒ Boolean
21 22 23 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 21 def self.a_subject_block?(block_ast) Solargraph::Rspec::SUBJECT_METHODS.include?(method_with_block_name(block_ast)) end |
.context_description_node(block_ast) ⇒ ::Parser::AST::Node?
62 63 64 65 66 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 62 def self.context_description_node(block_ast) return nil unless a_context_block?(block_ast) block_ast.children[0].children[2] end |
.let_method_name(block_ast) ⇒ String?
70 71 72 73 74 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 70 def self.let_method_name(block_ast) return nil unless a_block?(block_ast) block_ast.children[0].children[2]&.children&.[](0)&.to_s # rubocop:disable Style/SafeNavigationChainLength end |
.method_with_block_name(block_ast) ⇒ String?
Returns The name of the thing you are calling the block on.
53 54 55 56 57 58 |
# File 'lib/solargraph/rspec/spec_walker/node_types.rb', line 53 def self.method_with_block_name(block_ast) return nil unless a_block?(block_ast) return nil unless block_ast.children[0].type == :send block_ast.children[0].children[1].to_s end |