-
Notifications
You must be signed in to change notification settings - Fork 136
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
2 changed files
with
69 additions
and
4 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
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
module RubyLsp | ||
module Tapioca | ||
class AddonSpec < Minitest::HooksSpec | ||
class AddonSpec < ::Tapioca::SpecWithProject | ||
# The approach here is based on tests within the Ruby LSP Rails gem | ||
|
||
it "generates DSL RBIs for a given constant" do | ||
|
@@ -29,6 +29,51 @@ class AddonSpec < Minitest::HooksSpec | |
FileUtils.rm_rf("spec/dummy/sorbet/rbi") | ||
end | ||
|
||
it "generates gem RBIs" do | ||
@project.write!("config/environment.rb", <<~RB) | ||
require_relative "application.rb" | ||
RB | ||
|
||
@project.write!("config/application.rb", <<~RB) | ||
require "rails" | ||
module Test | ||
class Application < Rails::Application | ||
end | ||
end | ||
RB | ||
|
||
@project.require_real_gem("rails") | ||
|
||
content = File.read("spec/dummy/bin/rails") | ||
@project.write!("bin/rails", content) | ||
create_client(@project.absolute_path) | ||
FOO_RB = <<~RB | ||
module Foo | ||
end | ||
RB | ||
foo = mock_gem("foo", "0.0.1") do | ||
write!("lib/foo.rb", FOO_RB) | ||
end | ||
@project.write!("Gemfile", @project.tapioca_gemfile) | ||
@project.require_mock_gem(foo) | ||
@project.bundle_install! | ||
|
||
@client.delegate_notification( | ||
server_addon_name: "Tapioca", | ||
request_name: "gem", | ||
added_or_modified_gems: ["foo"], | ||
removed_gems: ["bar"], # TODO: handle removal (separate test) | ||
) | ||
wait_until_exists(@project.absolute_path_to("sorbet/rbi/gems/[email protected]")) | ||
|
||
shutdown_client | ||
|
||
assert_path_exists(@project.absolute_path_to("sorbet/rbi/gems/[email protected]")) | ||
ensure | ||
FileUtils.rm_rf("spec/dummy/sorbet/rbi") | ||
end | ||
|
||
it "triggers route DSL generation if routes.rb is modified" do | ||
create_client | ||
|
||
|
@@ -70,9 +115,9 @@ class AddonSpec < Minitest::HooksSpec | |
private | ||
|
||
# Starts a new client | ||
def create_client | ||
def create_client(path = "spec/dummy") | ||
@outgoing_queue = Thread::Queue.new | ||
@client = FileUtils.chdir("spec/dummy") do | ||
@client = FileUtils.chdir(path) do | ||
RubyLsp::Rails::RunnerClient.new(@outgoing_queue) | ||
end | ||
|
||
|
@@ -99,7 +144,10 @@ def wait_until_exists(path) | |
sleep(0.2) until File.exist?(path) | ||
end | ||
rescue Timeout::Error | ||
flunk("#{path} was not created in time") | ||
# flunk("#{path} was not created in time") | ||
while (msg = @outgoing_queue.pop) | ||
puts msg.params.message | ||
end | ||
end | ||
end | ||
end | ||
|