-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathrspec_test_current_line.py
More file actions
41 lines (31 loc) · 1.06 KB
/
rspec_test_current_line.py
File metadata and controls
41 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from typing import cast
import sublime
import sublime_plugin
class RspecTestCurrentLineCommand(sublime_plugin.WindowCommand):
def run(self):
view = self.window.active_view()
if view is None:
return
file = view.file_name()
if file is None:
return
rows = [view.rowcol(sel.a)[0] + 1 for sel in view.sel()]
cwd: "str | None" = cast(
str,
sublime.expand_variables(
r"${project_path:${folder:${file_path}}}",
sublime.active_window().extract_variables(),
),
)
exec_args: sublime.CommandArgs = {
"cmd": ["bundle", "exec", "rspec", f"{file}:{':'.join(map(str, rows))}"],
"working_dir": cwd,
"quiet": False,
}
self.window.run_command("exec", exec_args)
def is_enabled(self):
view = self.window.active_view()
if view is None:
return False
syntax = view.syntax()
return syntax is not None and syntax.scope == "source.ruby.rspec"