5
5
6
6
class GoToRelevantFileTest < Minitest ::Test
7
7
def test_when_input_is_test_file_returns_array_of_implementation_file_locations
8
+ stub_directory_structure ( "/workspace/test/requests" , has_test_dir : false )
8
9
stub_glob_pattern ( "**/go_to_relevant_file.rb" , [ "lib/ruby_lsp/requests/go_to_relevant_file.rb" ] )
9
10
10
11
test_file_path = "/workspace/test/requests/go_to_relevant_file_test.rb"
@@ -15,8 +16,12 @@ def test_when_input_is_test_file_returns_array_of_implementation_file_locations
15
16
end
16
17
17
18
def test_when_input_is_implementation_file_returns_array_of_test_file_locations
18
- pattern =
19
- "**/{{test_,spec_,integration_test_}go_to_relevant_file,go_to_relevant_file{_test,_spec,_integration_test}}.rb"
19
+ stub_directory_structure ( "/workspace/lib/ruby_lsp/requests" , has_test_dir : false )
20
+ stub_directory_structure ( "/workspace/lib/ruby_lsp" , has_test_dir : false )
21
+ stub_directory_structure ( "/workspace/lib" , has_test_dir : false )
22
+ stub_directory_structure ( "/workspace" , has_test_dir : true )
23
+
24
+ pattern = "**/{{test_,spec_,integration_test_}go_to_relevant_file,go_to_relevant_file{_test,_spec,_integration_test}}.rb"
20
25
stub_glob_pattern ( pattern , [ "test/requests/go_to_relevant_file_test.rb" ] )
21
26
22
27
impl_path = "/workspace/lib/ruby_lsp/requests/go_to_relevant_file.rb"
@@ -149,6 +154,21 @@ def test_it_finds_integration_tests_for_implementation
149
154
private
150
155
151
156
def stub_glob_pattern ( pattern , matches )
152
- Dir . stubs ( :glob ) . with ( pattern ) . returns ( matches )
157
+ absolute_pattern = pattern . start_with? ( "/" ) ? pattern : "/workspace/#{ pattern } "
158
+ absolute_matches = matches . map { |match | match . start_with? ( "/" ) ? match : "/workspace/#{ match } " }
159
+ Dir . stubs ( :glob ) . with ( absolute_pattern ) . returns ( absolute_matches )
160
+ end
161
+
162
+ def stub_directory_structure ( dir_path , has_test_dir :)
163
+ File . stubs ( :directory? ) . with ( File . join ( dir_path , "other_dir" ) ) . returns ( true )
164
+
165
+ if has_test_dir
166
+ Dir . stubs ( :entries ) . with ( dir_path ) . returns ( [ "." , ".." , "test" , "lib" , "other_dir" ] )
167
+ File . stubs ( :directory? ) . with ( File . join ( dir_path , "test" ) ) . returns ( true )
168
+ File . stubs ( :directory? ) . with ( File . join ( dir_path , "lib" ) ) . returns ( true )
169
+ else
170
+ Dir . stubs ( :entries ) . with ( dir_path ) . returns ( [ "." , ".." , "some_file.rb" , "other_dir" ] )
171
+ File . stubs ( :directory? ) . with ( File . join ( dir_path , "some_file.rb" ) ) . returns ( false )
172
+ end
153
173
end
154
174
end
0 commit comments