Skip to content

Commit

Permalink
Add test helper methods from Rails add-on
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Dec 17, 2024
1 parent 53cbea6 commit 03ca706
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/ruby_lsp/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,37 @@ def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typec
server.run_shutdown
end
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)

if result.is_a?(RubyLsp::Error)
raise "Failed to execute request #{result.message}"
else
result
end
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
5 changes: 5 additions & 0 deletions sorbet/rbi/shims/test_helper.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# typed: true

module RubyLsp::TestHelper
include Kernel # for `raise`
end

0 comments on commit 03ca706

Please sign in to comment.