@@ -7,8 +7,6 @@ module RubyLsp
77 module Rails
88 class HoverTest < ActiveSupport ::TestCase
99 setup do
10- File . write ( "#{ Dir . pwd } /test/dummy/tmp/app_uri.txt" , "http://localhost:3000" )
11- @client = RailsClient . new
1210 @message_queue = Thread ::Queue . new
1311
1412 # Build the Rails documents index ahead of time
@@ -23,7 +21,7 @@ class HoverTest < ActiveSupport::TestCase
2321
2422 test "hook returns model column information" do
2523 expected_response = {
26- schema_file : "#{ @client . root } /db/schema.rb" ,
24+ schema_file : "#{ dummy_root } /db/schema.rb" ,
2725 columns : [
2826 [ "id" , "integer" ] ,
2927 [ "first_name" , "string" ] ,
@@ -34,8 +32,7 @@ class HoverTest < ActiveSupport::TestCase
3432 ] ,
3533 }
3634
37- stub_http_request ( "200" , expected_response . to_json )
38- @client . stubs ( :check_if_server_is_running! )
35+ RunnerClient . any_instance . stubs ( model : expected_response )
3936
4037 response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
4138 class User < ApplicationRecord
@@ -50,7 +47,7 @@ class User < ApplicationRecord
5047 ```
5148
5249 **Definitions**: [fake.rb](file:///fake.rb#L1,1-2,4)
53- [Schema](file://#{ @client . root } /db/schema.rb)
50+ [Schema](file://#{ dummy_root } /db/schema.rb)
5451
5552
5653 **id**: integer
@@ -69,7 +66,7 @@ class User < ApplicationRecord
6966
7067 test "return column information for namespaced models" do
7168 expected_response = {
72- schema_file : "#{ @client . root } /db/schema.rb" ,
69+ schema_file : "#{ dummy_root } /db/schema.rb" ,
7370 columns : [
7471 [ "id" , "integer" ] ,
7572 [ "first_name" , "string" ] ,
@@ -80,8 +77,7 @@ class User < ApplicationRecord
8077 ] ,
8178 }
8279
83- stub_http_request ( "200" , expected_response . to_json )
84- @client . stubs ( :check_if_server_is_running! )
80+ RunnerClient . any_instance . stubs ( model : expected_response )
8581
8682 response = hover_on_source ( <<~RUBY , { line : 4 , character : 6 } )
8783 module Blog
@@ -93,7 +89,7 @@ class User < ApplicationRecord
9389 RUBY
9490
9591 assert_equal ( <<~CONTENT . chomp , response . contents . value )
96- [Schema](file://#{ @client . root } /db/schema.rb)
92+ [Schema](file://#{ dummy_root } /db/schema.rb)
9793
9894 **id**: integer
9995
@@ -111,12 +107,11 @@ class User < ApplicationRecord
111107
112108 test "handles `db/structure.sql` instead of `db/schema.rb`" do
113109 expected_response = {
114- schema_file : "#{ @client . root } /db/structure.sql" ,
110+ schema_file : "#{ dummy_root } /db/structure.sql" ,
115111 columns : [ ] ,
116112 }
117113
118- stub_http_request ( "200" , expected_response . to_json )
119- @client . stubs ( :check_if_server_is_running! )
114+ RunnerClient . any_instance . stubs ( model : expected_response )
120115
121116 response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
122117 class User < ApplicationRecord
@@ -127,7 +122,7 @@ class User < ApplicationRecord
127122
128123 assert_includes (
129124 response . contents . value ,
130- "[Schema](file://#{ @client . root } /db/structure.sql)" ,
125+ "[Schema](file://#{ dummy_root } /db/structure.sql)" ,
131126 )
132127 end
133128
@@ -137,8 +132,7 @@ class User < ApplicationRecord
137132 columns : [ ] ,
138133 }
139134
140- stub_http_request ( "200" , expected_response . to_json )
141- @client . stubs ( :check_if_server_is_running! )
135+ RunnerClient . any_instance . stubs ( model : expected_response )
142136
143137 response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
144138 class User < ApplicationRecord
@@ -213,6 +207,10 @@ def hover_on_source(source, position)
213207 assert_nil ( response . error )
214208 response . response
215209 end
210+
211+ def dummy_root
212+ File . expand_path ( "#{ __dir__ } /../../test/dummy" )
213+ end
216214 end
217215 end
218216end
0 commit comments