Skip to content
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

Extract TestUtils #548

Closed
wants to merge 2 commits into from
Closed
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
45 changes: 45 additions & 0 deletions lib/ruby_lsp/ruby_lsp_rails/test_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# typed: strict
# frozen_string_literal: true

module RubyLsp
module Rails
module TestUtils
extend T::Sig
extend T::Helpers
include Minitest::Assertions # to prevent Sorbet complaining

sig { params(server: RubyLsp::Server).returns(RubyLsp::Result) }
def pop_result(server)
result = server.pop_response
result = server.pop_response until result.is_a?(RubyLsp::Result) || result.is_a?(RubyLsp::Error)

refute_instance_of(
RubyLsp::Error,
result,
-> { "Failed to execute request #{T.cast(result, RubyLsp::Error).message}" },
)
T.cast(result, RubyLsp::Result)
end

# TODO: write correct sig
sig { params(message_queue: T.untyped, type: T.untyped).returns(T.untyped) }
def pop_log_notification(message_queue, type)
log = message_queue.pop
return log if log.params.type == type

log = message_queue.pop until log.params.type == type
log
end

# TODO: write correct sig
sig { params(outgoing_queue: T.untyped, block: T.untyped).returns(T.untyped) }
def pop_message(outgoing_queue, &block)
message = outgoing_queue.pop
return message if block.call(message)

message = outgoing_queue.pop until block.call(message)
message
end
end
end
end
34 changes: 3 additions & 31 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require "ruby_lsp/internal"
require "ruby_lsp/test_helper"
require "ruby_lsp/ruby_lsp_rails/addon"
require "ruby_lsp/ruby_lsp_rails/test_utils"

if defined?(DEBUGGER__)
DEBUGGER__::CONFIG[:skip_path] =
Expand All @@ -28,40 +29,11 @@

module ActiveSupport
class TestCase
extend T::Sig
include RubyLsp::TestHelper

def dummy_root
File.expand_path("#{__dir__}/dummy")
end

sig { params(server: RubyLsp::Server).returns(RubyLsp::Result) }
def pop_result(server)
result = server.pop_response
result = server.pop_response until result.is_a?(RubyLsp::Result) || result.is_a?(RubyLsp::Error)

refute_instance_of(
RubyLsp::Error,
result,
-> { "Failed to execute request #{T.cast(result, RubyLsp::Error).message}" },
)
T.cast(result, RubyLsp::Result)
end

def pop_log_notification(message_queue, type)
log = message_queue.pop
return log if log.params.type == type

log = message_queue.pop until log.params.type == type
log
end

def pop_message(outgoing_queue, &block)
message = outgoing_queue.pop
return message if block.call(message)

message = outgoing_queue.pop until block.call(message)
message
end
include RubyLsp::TestHelper
include RubyLsp::Rails::TestUtils
end
end
Loading