From 07be9377ef18e7ca1c82cd104491363c2e344d9b Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:28:54 -0500 Subject: [PATCH] Extract TestUtils --- lib/ruby_lsp/ruby_lsp_rails/test_utils.rb | 41 +++++++++++++++++++++++ test/test_helper.rb | 34 ++----------------- 2 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 lib/ruby_lsp/ruby_lsp_rails/test_utils.rb diff --git a/lib/ruby_lsp/ruby_lsp_rails/test_utils.rb b/lib/ruby_lsp/ruby_lsp_rails/test_utils.rb new file mode 100644 index 00000000..61e30018 --- /dev/null +++ b/lib/ruby_lsp/ruby_lsp_rails/test_utils.rb @@ -0,0 +1,41 @@ +# typed: strict +# frozen_string_literal: true + +# NOTE: These + +module RubyLsp + module Rails + module TestUtils + extend T::Sig + + 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 + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index ca2195c5..02056d60 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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] = @@ -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