Skip to content

Commit 78f45b1

Browse files
committed
wip
1 parent a89f3a2 commit 78f45b1

16 files changed

+74
-30
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ gem "sorbet-static-and-runtime", platforms: :ruby
1818
gem "tapioca", "~> 0.13", require: false, platforms: :ruby
1919
gem "psych", "~> 5.1", require: false
2020
gem "rails", "8.0.0.beta1"
21+
gem "test_declarative"
2122

2223
platforms :mingw, :x64_mingw, :mswin, :jruby do
2324
gem "tzinfo"

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ GEM
250250
spoom (>= 1.2.0)
251251
thor (>= 1.2.0)
252252
yard-sorbet
253+
test_declarative (0.0.6)
253254
thor (1.3.2)
254255
timeout (0.4.1)
255256
tzinfo (2.0.6)
@@ -289,6 +290,7 @@ DEPENDENCIES
289290
sorbet-static-and-runtime
290291
sqlite3
291292
tapioca (~> 0.13)
293+
test_declarative
292294
tzinfo
293295
tzinfo-data
294296

Rakefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ require "rake/testtask"
1313
Rake::TestTask.new(:test) do |t|
1414
t.libs << "test"
1515
t.libs << "lib"
16-
t.test_files = FileList["test/**/*_test.rb"]
16+
t.test_files = FileList["test/**/*_test.rb"] - ["test/ruby_lsp_rails/server_test.rb"]
1717
end
1818

19-
task default: [:"db:setup", :test]
19+
Rake::TestTask.new("test:server") do |t|
20+
t.libs << "test"
21+
t.libs << "lib"
22+
t.test_files = ["test/ruby_lsp_rails/server_test.rb"]
23+
end
24+
25+
task default: [:"db:setup", :test, "test:server"]

gemfiles/Gemfile-rails-main

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ gem "sorbet-static-and-runtime", platforms: :ruby
1919
gem "tapioca", "~> 0.11", require: false, platforms: :ruby
2020
gem "psych", "~> 5.1", require: false
2121
gem "rails", github: "rails/rails", branch: "main"
22+
gem "test_declarative"
2223
gem "webmock"
2324

2425
platforms :mingw, :x64_mingw, :mswin, :jruby do

test/ruby_lsp_rails/addon_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module RubyLsp
77
module Rails
8-
class AddonTest < ActiveSupport::TestCase
8+
class AddonTest < Minitest::Test
99
test "name returns add-on name" do
1010
addon = Addon.new
1111
assert_equal("Ruby LSP Rails", addon.name)

test/ruby_lsp_rails/code_lens_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
module RubyLsp
77
module Rails
8-
class CodeLensTest < ActiveSupport::TestCase
9-
setup do
8+
class CodeLensTest < Minitest::Test
9+
def setup
1010
GlobalState.any_instance.stubs(:test_library).returns("rails")
1111
@ruby = Gem.win_platform? ? "ruby.exe" : "ruby"
1212
end

test/ruby_lsp_rails/definition_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module RubyLsp
77
module Rails
8-
class DefinitionTest < ActiveSupport::TestCase
8+
class DefinitionTest < Minitest::Test
99
test "recognizes model callback with multiple symbol arguments" do
1010
response = generate_definitions_for_source(<<~RUBY, { line: 3, character: 18 })
1111
# typed: false

test/ruby_lsp_rails/document_symbol_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module RubyLsp
77
module Rails
8-
class DocumentSymbolTest < ActiveSupport::TestCase
8+
class DocumentSymbolTest < Minitest::Test
99
test "recognizes Rails Active Support test cases" do
1010
response = generate_document_symbols_for_source(<<~RUBY)
1111
class Test < ActiveSupport::TestCase

test/ruby_lsp_rails/hover_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module RubyLsp
77
module Rails
8-
class HoverTest < ActiveSupport::TestCase
8+
class HoverTest < Minitest::Test
99
test "hook returns model column information" do
1010
expected_response = {
1111
schema_file: "#{dummy_root}/db/schema.rb",

test/ruby_lsp_rails/indexing_enhancement_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module RubyLsp
77
module Rails
8-
class IndexingEnhancementTest < ActiveSupport::TestCase
8+
class IndexingEnhancementTest < Minitest::Test
99
class << self
1010
# For these tests, it's convenient to have the index fully populated with Rails information, but we don't have
1111
# to reindex on every single example or that will be too slow

test/ruby_lsp_rails/launch_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module RubyLsp
77
module Rails
8-
class LaunchTest < ActiveSupport::TestCase
8+
class LaunchTest < Minitest::Test
99
test "launching the client succeeds" do
1010
outgoing_queue = Thread::Queue.new
1111

test/ruby_lsp_rails/runner_client_test.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
module RubyLsp
88
module Rails
9-
class RunnerClientTest < ActiveSupport::TestCase
10-
setup do
9+
class RunnerClientTest < Minitest::Test
10+
def setup
1111
@outgoing_queue = Thread::Queue.new
1212
@client = T.let(RunnerClient.new(@outgoing_queue), RunnerClient)
1313
end
1414

15-
teardown do
15+
def teardown
1616
@client.shutdown
1717

1818
# On Windows, the server process sometimes takes a lot longer to shutdown and may end up getting force killed,
@@ -156,8 +156,10 @@ def execute(request, params)
156156
end
157157
end
158158

159-
class NullClientTest < ActiveSupport::TestCase
160-
setup { @client = NullClient.new }
159+
class NullClientTest < Minitest::Test
160+
def setup
161+
@client = NullClient.new
162+
end
161163

162164
test "#shutdown is a no-op" do
163165
assert_nothing_raised { @client.shutdown }

test/ruby_lsp_rails/server_test.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22
# frozen_string_literal: true
33

44
require "test_helper"
5+
6+
# Configure Rails Environment
7+
ENV["RAILS_ENV"] = "test"
8+
9+
require_relative "../dummy/config/environment"
10+
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
11+
ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__)
12+
513
require "ruby_lsp/ruby_lsp_rails/server"
614

7-
class ServerTest < ActiveSupport::TestCase
8-
setup do
15+
class ServerTest < Minitest::Test
16+
def setup
917
@stdout = StringIO.new
1018
@server = RubyLsp::Rails::Server.new(stdout: @stdout, override_default_output_device: false)
1119
end

test/ruby_lsp_rails/support/location_builder_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module RubyLsp
77
module Rails
88
module Support
9-
class LocationBuilderTest < ActiveSupport::TestCase
9+
class LocationBuilderTest < Minitest::Test
1010
test "line_location_from_s raises argument error if invalid string given" do
1111
assert_raises(ArgumentError) { LocationBuilder.line_location_from_s("banana") }
1212
end

test/ruby_lsp_rails_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
require "test_helper"
55

66
module RubyLsp
7-
class RailsTest < ActiveSupport::TestCase
7+
class RailsTest < Minitest::Test
88
test "it has a version number" do
99
assert RubyLsp::Rails::VERSION
1010
end

test/test_helper.rb

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
# typed: true
22
# frozen_string_literal: true
33

4-
# Configure Rails Environment
5-
ENV["RAILS_ENV"] = "test"
6-
7-
require_relative "../test/dummy/config/environment"
8-
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
9-
ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__)
10-
require "sorbet-runtime"
11-
require "rails/test_help"
12-
require "mocha/minitest"
134
require "ruby_lsp/internal"
5+
require "minitest/autorun"
6+
require "test_declarative"
7+
require "mocha/minitest"
148
require "ruby_lsp/test_helper"
159
require "ruby_lsp/ruby_lsp_rails/addon"
1610

@@ -26,8 +20,8 @@
2620
# Tapioca (and thus Spoom) is not available on Windows
2721
end
2822

29-
module ActiveSupport
30-
class TestCase
23+
module Minitest
24+
class Test
3125
extend T::Sig
3226
include RubyLsp::TestHelper
3327

@@ -63,5 +57,35 @@ def pop_message(outgoing_queue, &block)
6357
message = outgoing_queue.pop until block.call(message)
6458
message
6559
end
60+
61+
# Copied from Rails
62+
def assert_nothing_raised(*args)
63+
msg = if Module === args.last
64+
nil
65+
else
66+
args.pop
67+
end
68+
begin
69+
line = __LINE__
70+
yield
71+
rescue MiniTest::Skip
72+
raise
73+
rescue Exception => e # rubocop:disable Lint/RescueException
74+
bt = e.backtrace
75+
as = e.instance_of?(MiniTest::Assertion)
76+
if as
77+
ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /
78+
bt.reject! { |ln| ans =~ ln }
79+
end
80+
if (args.empty? && !as) ||
81+
args.any? { |a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a }
82+
msg = message(msg) { "Exception raised:\n<#{mu_pp(e)}>" }
83+
raise MiniTest::Assertion, msg.call, bt
84+
else
85+
raise
86+
end
87+
end
88+
nil
89+
end
6690
end
6791
end

0 commit comments

Comments
 (0)