How to use file-sniper-test file

I am using Emacs and the shell and trying to set the path to the test file to use projectile-toggle-between-implementation-and-test .

I call Mx projectile-find-test-file , but the Helm buffer is empty. No matter what I put in the pattern field, a file is not displayed in the Helm buffer to select and enter the path to the test file relative to the project root, it simply causes the Dired buffer to open in the project root.

Please advise how to use projectile-find-test-file

+5
source share
2 answers

projectile guesses the name of the test file specified by the source file by adding a suffix / prefix to the source file. For example, if you have hello.rb , then it tries to find a file called hello_test.rb in your project.

By default, it has some rules that map to the type of project for checking the suffix / prefix. Here is the actual code:

 (defun projectile-test-suffix (project-type) "Find default test files suffix based on PROJECT-TYPE." (cond ((member project-type '(rails-rspec ruby-rspec)) "_spec") ((member project-type '(rails-test ruby-test lein-test go)) "_test") ((member project-type '(scons)) "test") ((member project-type '(maven symfony)) "Test") ((member project-type '(gradle grails)) "Spec"))) 

If you do not see anything in projectile-find-test-file , it means that most likely it cannot find anything related to your source file by adding a suffix / prefix.

This can be configured using projectile-test-suffix-function . By default, a variable points to the function above, but you can override it with your own rules.

+6
source

This is not a great answer to your question, but projectile-find-test-file just hung for me before I received the invitation. I had no inclination to find out what was going on there, so I just created:

 (defun my-test-prefix (project-type) "test_") 

and configure projectile-test-function-prefix to point this out. For me this worked projectile-toggle-between-implementation-and-test , which I really need.

+3
source

Source: https://habr.com/ru/post/1244463/


All Articles