diff --git a/lib/ruby_lsp/tapioca/server_addon.rb b/lib/ruby_lsp/tapioca/server_addon.rb index 888b5e377..2f36df37a 100644 --- a/lib/ruby_lsp/tapioca/server_addon.rb +++ b/lib/ruby_lsp/tapioca/server_addon.rb @@ -5,6 +5,7 @@ require "tapioca/dsl/compilers/url_helpers" require "tapioca/dsl/compilers/active_record_fixtures" require "active_support/test_case" # need? +require "tapioca/dsl/compilers/url_helpers" module RubyLsp module Tapioca diff --git a/spec/tapioca/addon_spec.rb b/spec/tapioca/addon_spec.rb index e78341290..b5e202534 100644 --- a/spec/tapioca/addon_spec.rb +++ b/spec/tapioca/addon_spec.rb @@ -20,6 +20,8 @@ class AddonSpec < Minitest::HooksSpec request_name: "dsl", constants: ["NotifyUserJob"], ) + wait_until_exists("spec/dummy/sorbet/rbi/dsl/notify_user_job.rbi") + shutdown_client assert_path_exists("spec/dummy/sorbet/rbi/dsl/notify_user_job.rbi") @@ -55,6 +57,7 @@ class AddonSpec < Minitest::HooksSpec type: Constant::FileChangeType::CREATED, }]) + wait_until_exists("spec/dummy/sorbet/rbi/dsl/generated_path_helpers_module.rbi") shutdown_client assert_match("rails_info_routes_path", File.read("spec/dummy/sorbet/rbi/dsl/generated_path_helpers_module.rbi")) @@ -64,7 +67,7 @@ class AddonSpec < Minitest::HooksSpec FileUtils.rm("spec/dummy/config/routes.rb") if File.exist?("spec/dummy/config/routes.rb") end - it "triggers fixtures DSL generation if fixtures are modified" do + it "trigger fixtures DSL generate if a fixture is modified" do create_client global_state = RubyLsp::GlobalState.new @@ -82,19 +85,24 @@ class AddonSpec < Minitest::HooksSpec addon.instance_variable_set(:@index, global_state.index) addon.instance_variable_set(:@outgoing_queue, @outgoing_queue) - File.write("test/fixtures/foo.yml", "") + # TODO create test/fixtures ? + File.write("test/fixtures/users.yml", <<~RUBY) + # contents? + RUBY addon.workspace_did_change_watched_files([{ - uri: "file://#{Dir.pwd}/test/fixtures/foo.yml", + uri: "file://#{Dir.pwd}/test/fixtures/users.yml", type: Constant::FileChangeType::CREATED, }]) + wait_until_exists("spec/dummy/sorbet/rbi/dsl/active_record/test_fixtures.rbi") shutdown_client - assert_match("def foo", File.read("spec/dummy/sorbet/rbi/dsl/generated_url_helpers_module.rbi")) + # assert_match("rails_info_routes_path", File.read("spec/dummy/sorbet/rbi/dsl/generated_path_helpers_module.rbi")) + # assert_match("rails_info_routes_url", File.read("spec/dummy/sorbet/rbi/dsl/generated_url_helpers_module.rbi")) ensure - # FileUtils.rm_rf("spec/dummy/sorbet/rbi") # TODO: fix path - FileUtils.rm("test/fixtures/foo.yml") if File.exist?("test/fixtures/foo.yml") + # FileUtils.rm_rf("spec/dummy/sorbet/rbi") + FileUtils.rm("test/fixtures/users.yml") if File.exist?("test/fixtures/users.yml") end private @@ -117,22 +125,20 @@ def create_client # Triggers shutdown and waits for it to complete def shutdown_client - Thread.new do - @client.shutdown - @client.instance_variable_get(:@wait_thread).join - - begin - # Since the Tapioca server add-on forks, there are no guarantees that the forked process will finish while - # we shutdown the client. We need to make sure the child processes are done before continuing - Process.wait - rescue Errno::ECHILD - # The forked process finished before we waited - end - end.join + @client.shutdown + @client.instance_variable_get(:@wait_thread).join assert_predicate(@client, :stopped?) @outgoing_queue.close end + + def wait_until_exists(path) + Timeout.timeout(4) do + sleep(0.2) until File.exist?(path) + end + rescue Timeout::Error + flunk("#{path} was not created in time") + end end end end