Skip to content

Check test framework only before pushing test code lens #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/ruby_lsp/ruby_lsp_rails/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def deactivate
).void
end
def create_code_lens_listener(response_builder, uri, dispatcher)
return unless T.must(@global_state).test_library == "rails"

CodeLens.new(@client, response_builder, uri, dispatcher)
CodeLens.new(@client, T.must(@global_state), response_builder, uri, dispatcher)
end

sig do
Expand Down
5 changes: 4 additions & 1 deletion lib/ruby_lsp/ruby_lsp_rails/code_lens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ class CodeLens
sig do
params(
client: RunnerClient,
global_state: GlobalState,
response_builder: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens],
uri: URI::Generic,
dispatcher: Prism::Dispatcher,
).void
end
def initialize(client, response_builder, uri, dispatcher)
def initialize(client, global_state, response_builder, uri, dispatcher)
@client = client
@global_state = global_state
@response_builder = response_builder
@path = T.let(uri.to_standardized_path, T.nilable(String))
@group_id = T.let(1, Integer)
Expand Down Expand Up @@ -230,6 +232,7 @@ def add_migrate_code_lens(node, name:, command:)
sig { params(node: Prism::Node, name: String, command: String, kind: Symbol).void }
def add_test_code_lens(node, name:, command:, kind:)
return unless @path
return unless @global_state.test_library == "rails"

arguments = [
@path,
Expand Down
23 changes: 23 additions & 0 deletions test/ruby_lsp_rails/code_lens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,29 @@ def index
assert_empty(response)
end

test "returns code lenses despite different test framework" do
RubyLsp::GlobalState.any_instance.stubs(:test_library).returns("rspec")

response = generate_code_lens_for_source(<<~RUBY)
class UsersController < ApplicationController
def index
end
end
RUBY

refute_empty(response)

response = generate_code_lens_for_source(<<~RUBY, file: "file://db/migrate/123456_add_first_name_to_users.rb")
class AddFirstNameToUsers < ActiveRecord::Migration[7.1]
def change
add_column(:users, :first_name, :string)
end
end
RUBY

refute_empty(response)
end

private

attr_reader :ruby
Expand Down
Loading