-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ | |
/spec/reports/ | ||
/tmp/ | ||
/vendor/ | ||
/test/dummy/log/ | ||
/test/dummy/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
# Configure Rails Environment | ||
ENV["RAILS_ENV"] = "test" | ||
|
||
require "minitest/spec" | ||
require "ruby_lsp/internal" | ||
require "ruby_lsp/test_helper" | ||
|
||
module ActiveSupport | ||
class TestCase | ||
include RubyLsp::TestHelper | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "addon_spec_helper" | ||
require "ruby_lsp/ruby_lsp_rails/runner_client" | ||
require "spoom/context" | ||
require "minitest/hooks" | ||
|
||
module RubyLsp | ||
module Tapioca | ||
class RunnerClientTest < Minitest::HooksSpec | ||
# The approach here is based on tests within the Ruby LSP Rails gem | ||
|
||
before do | ||
FileUtils.cp("test/dummy/bin/rails", "bin/rails") | ||
@outgoing_queue = Thread::Queue.new | ||
@client = T.let(RubyLsp::Rails::RunnerClient.new(@outgoing_queue), RubyLsp::Rails::RunnerClient) | ||
end | ||
|
||
after do | ||
@client.shutdown | ||
|
||
# On Windows, the server process sometimes takes a lot longer to shutdown and may end up getting force killed, | ||
# which makes this assertion flaky | ||
assert_predicate(@client, :stopped?) unless Gem.win_platform? | ||
@outgoing_queue.close | ||
FileUtils.rm("bin/rails") | ||
end | ||
|
||
EXPECTED_RBI_PATH = "sorbet/rbi/dsl/notify_user_job.rbi" | ||
it "generates DSL RBIs for a gem" do | ||
raise "RBI already exists" if File.exist?(EXPECTED_RBI_PATH) | ||
|
||
addon_path = File.expand_path("lib/ruby_lsp/tapioca/server_addon.rb") | ||
@client.register_server_addon(File.expand_path(addon_path)) | ||
@client.delegate_notification( | ||
server_addon_name: "Tapioca", | ||
request_name: "dsl", | ||
constants: ["NotifyUserJob"], | ||
) | ||
|
||
begin | ||
Timeout.timeout(10) do | ||
until File.exist?(EXPECTED_RBI_PATH) | ||
end | ||
end | ||
rescue Timeout::Error | ||
flunk("RBI file was not generated") | ||
end | ||
ensure | ||
FileUtils.rm_f(EXPECTED_RBI_PATH) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class NotifyUserJob < ActiveJob::Base | ||
def perform(user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# This command will automatically be run when you run "rails" with Rails gems | ||
# installed from the root of your application. | ||
|
||
ENGINE_ROOT = File.expand_path("..", __dir__) | ||
APP_PATH = File.expand_path("../test/dummy/config/application", __dir__) | ||
|
||
# Set up gems listed in the Gemfile. | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) | ||
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) | ||
|
||
require "rails/engine/commands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
require_relative "config/environment" | ||
|
||
run Rails.application | ||
Rails.application.load_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) | ||
|
||
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) | ||
$LOAD_PATH.unshift(File.expand_path("../../../lib", __dir__)) | ||
|
||
require "rails" # minimal, instead of "rails/all" | ||
require "active_job/railtie" | ||
|
||
Bundler.require(*Rails.groups) | ||
|
||
module Dummy | ||
class Application < Rails::Application | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "application" | ||
|
||
Rails.application.initialize! |