Skip to content

Commit

Permalink
Ignore context and describe calls without arguments (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 authored Jan 16, 2024
1 parent a58e6d4 commit 18727da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/ruby_lsp/ruby_lsp_rspec/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def on_call_node_enter(node)
name = generate_name(node)
add_test_code_lens(node, name: name, kind: :example)
when "context", "describe"
return if node.receiver && node.receiver&.slice != "RSpec"
return unless valid_group?(node)

name = generate_name(node)
add_test_code_lens(node, name: name, kind: :group)
Expand All @@ -64,12 +64,19 @@ def on_call_node_enter(node)
def on_call_node_leave(node)
case node.message
when "context", "describe"
return if node.receiver && node.receiver&.slice != "RSpec"
return unless valid_group?(node)

@group_id_stack.pop
end
end

private

sig { params(node: Prism::CallNode).returns(T::Boolean) }
def valid_group?(node)
!(node.block.nil? || (node.receiver && node.receiver&.slice != "RSpec"))
end

sig { params(node: Prism::CallNode).returns(String) }
def generate_name(node)
arguments = node.arguments&.arguments
Expand All @@ -92,8 +99,6 @@ def generate_name(node)
end
end

private

sig { params(node: Prism::Node, name: String, kind: Symbol).void }
def add_test_code_lens(node, name:, kind:)
line_number = node.location.start_line
Expand Down
5 changes: 5 additions & 0 deletions spec/ruby_lsp_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
describe var do
end
# these should bot be recognized
context
describe
context("foo")
RUBY

response = RubyLsp::Executor.new(store, message_queue).execute(
Expand Down

0 comments on commit 18727da

Please sign in to comment.