Skip to content

Commit 9c5b1f1

Browse files
authored
Fix SpecStyle to not receive Prism events (#71)
* Calling super will still register for events The parent class TestDiscovery also registers SpecStyle for Prism event. While handling the events it tries to access a nil variable when entering a class or module and thus completely break code analysis of normal ruby files. * Added a test to verify expected SpecStyle patch behavior * Added integration test to verify parsing of a simple ruby file The improperly patched SpecStyle would fail when the Ruby LSP was handling a 'textDocument/foldingRange' message (probably others too) for a source while with module and class blocks as it was still receiving events from Prism (which we do not want) for the RSpec addon.
1 parent 3ac0633 commit 9c5b1f1

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

lib/ruby_lsp/ruby_lsp_rspec/spec_style_patch.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Listeners
77
class SpecStyle
88
#: (ResponseBuilders::TestCollection, GlobalState, Prism::Dispatcher, URI::Generic) -> void
99
def initialize(response_builder, global_state, dispatcher, uri)
10-
super
10+
# nop
1111
end
1212
end
1313
end

spec/code_lens_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,37 @@
4343
expect(response[6].data).to eq({ kind: "run_test", arguments: [uri.to_standardized_path, "./spec/fake_spec.rb:1::./spec/fake_spec.rb:2::./spec/fake_spec.rb:3"] })
4444
end
4545
end
46+
47+
it "processes an ordinairy ruby file with module and class blocks" do
48+
source = <<~RUBY
49+
module RubyLspRSpecTests
50+
class ExampleClass
51+
def dummy
52+
# Test case to verify issue #71
53+
end
54+
end
55+
end
56+
RUBY
57+
58+
with_server(source) do |server, uri|
59+
allow(server.global_state).to receive(:enabled_feature?).with(:fullTestDiscovery).and_return(true)
60+
61+
server.process_message(
62+
{
63+
id: 1,
64+
method: "textDocument/foldingRange",
65+
params: {
66+
textDocument: { uri: uri },
67+
position: { line: 0, character: 0 },
68+
},
69+
},
70+
)
71+
72+
response = pop_result(server).response
73+
expect(response.count).to eq(3)
74+
# We are happy if processing the source did not bail with an error
75+
end
76+
end
4677
end
4778

4879
context "without full test discovery" do

spec/spec_style_patch_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe RubyLsp::Listeners::SpecStyle do
4+
describe "spec_style_patch" do
5+
it "disables initialization" do
6+
RubyLsp::Listeners::SpecStyle.new(double("response_builder"), double("global_state"), double("dispatcher"), double("uri"))
7+
end
8+
end
9+
end

0 commit comments

Comments
 (0)