Skip to content

Commit 1462179

Browse files
committed
Add command to run selected spec only
1 parent 46318c1 commit 1462179

3 files changed

Lines changed: 51 additions & 5 deletions

File tree

Default.sublime-commands

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
},
1111
{
12-
"caption": "RSpec: Open corresponding file",
12+
"caption": "RSpec: Toggle source/spec",
1313
"command": "rspec_toggle_source_or_spec"
1414
},
1515
{
@@ -19,5 +19,9 @@
1919
{
2020
"caption": "RSpec: Generate specification",
2121
"command": "rspec_generate_specification",
22+
},
23+
{
24+
"caption": "RSpec: Test current line",
25+
"command": "rspec_test_current_line",
2226
}
2327
]

messages/3.0.0.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ Report bugs or request features in the Github repo: https://github.com/SublimeTe
2121

2222
# Other improvements and new features
2323

24-
- General performance improvements to the command to toggle between spec and source.
25-
- In the case where a slow search has to be performed (non-standard layouts), the command now
26-
respects your global "folder_exclude_patterns" setting.
2724
- Added improved syntax, courtesy of @themilkman
2825
- Extended to include all RSpec matchers available in the latest version (3.13)
2926
- Scope commands so they don't appear when they are not relevant.
3027
- Fixed support for symbol lists. Now doing "Goto Symbol" inside an RSpec file will basically show the specification.
31-
- Added a command, "RSpec: Generate specification" that generates the specification in a new tab.
28+
- Added a "RSpec: Generate specification" command that generates the specification in a new tab.
29+
- Added a "RSpec: Test current line" command, supporting multiple selections.
30+
- General performance improvements to the command to toggle between spec and source.
31+
- In the case where a slow search has to be performed (non-standard layouts), the command now
32+
respects your global "folder_exclude_patterns" setting.

rspec_test_current_line.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from typing import cast
2+
3+
import sublime
4+
import sublime_plugin
5+
6+
7+
class RspecTestCurrentLineCommand(sublime_plugin.WindowCommand):
8+
def run(self):
9+
view = self.window.active_view()
10+
if view is None:
11+
return
12+
13+
file = view.file_name()
14+
if file is None:
15+
return
16+
17+
rows = [view.rowcol(sel.a)[0] + 1 for sel in view.sel()]
18+
19+
cwd: "str | None" = cast(
20+
str,
21+
sublime.expand_variables(
22+
r"${project_path:${folder:${file_path}}}",
23+
sublime.active_window().extract_variables(),
24+
),
25+
)
26+
27+
exec_args: sublime.CommandArgs = {
28+
"cmd": ["bundle", "exec", "rspec", f"{file}:{':'.join(map(str, rows))}"],
29+
"working_dir": cwd,
30+
"quiet": False,
31+
}
32+
33+
self.window.run_command("exec", exec_args)
34+
35+
def is_enabled(self):
36+
view = self.window.active_view()
37+
if view is None:
38+
return False
39+
40+
syntax = view.syntax()
41+
return syntax is not None and syntax.scope == "source.ruby.rspec"

0 commit comments

Comments
 (0)