Skip to content

Commit 1e0a1f0

Browse files
committed
Add command to generate specification
1 parent 775d571 commit 1e0a1f0

5 files changed

Lines changed: 48 additions & 1 deletion

File tree

Default.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
{
1616
"caption": "RSpec: Create new module",
1717
"command": "rspec_create_module"
18+
},
19+
{
20+
"caption": "RSpec: Generate specification",
21+
"command": "rspec_generate_specification",
1822
}
1923
]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ RSpec does not define default key bindings to avoid conflicts with other package
2929
* Command to go to the corresponding spec / source file (available in the Command Palette, can be configured to a keyboard shortcut)
3030
* Large amount of *RSpec* snippets
3131
* Symbol support: use Goto Symbol... inside an RSpec file and you will get a menu with the specification as you've defined it
32+
* You can also generate a structured document of a spec file with the "RSpec: Generate specification" command

generate_specification_command.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sublime
2+
import sublime_plugin
3+
4+
5+
class RspecGenerateSpecificationCommand(sublime_plugin.WindowCommand):
6+
def run(self):
7+
view = self.window.active_view()
8+
if view is None:
9+
return
10+
11+
symbols = view.symbol_regions()
12+
result = []
13+
for symbol in symbols:
14+
# Sublime automatically assigns NAMESPACE for "RSpec.describe" format
15+
# https://github.com/sublimehq/sublime_text/issues/3315
16+
if symbol.kind[0] in (sublime.KindId.KEYWORD, sublime.KindId.NAMESPACE):
17+
result.append(symbol.name)
18+
19+
doc_file = self.window.new_file()
20+
doc_file.set_name("RSpec specification")
21+
doc_file.set_scratch(True)
22+
doc_file.run_command("rspec_insert_content", {"text": "\n".join(result)})
23+
24+
def is_enabled(self):
25+
view = self.window.active_view()
26+
if view is None:
27+
return False
28+
29+
syntax = view.syntax()
30+
return syntax and syntax.scope == "source.ruby.rspec"

messages/3.0.0.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Report bugs or request features in the Github repo: https://github.com/SublimeTe
1919

2020

2121

22-
# Other improvements
22+
# Other improvements and new features
2323

2424
- Added improved syntax, courtesy of @themilkman
25+
- Extended to include all RSpec matchers available in the latest version (3.13)
2526
- Scope commands so they don't appear when they are not relevant.
2627
- Fixed support for symbol lists. Now doing "Goto Symbol" inside an RSpec file will basically show the specification.
28+
- Added a command, "RSpec: Generate specification" that generates the specification in a new tab.

shared.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
import sublime
2+
import sublime_plugin
3+
4+
15
def other_group_in_pair(window):
26
"""Returns the neighbour focus group for the current window."""
37
if window.active_group() % 2 == 0:
48
target_group = window.active_group() + 1
59
else:
610
target_group = window.active_group() - 1
711
return min(target_group, window.num_groups() - 1)
12+
13+
14+
# TODO: Call from RspecNewModuleCommand and RspecNewSpecCommand
15+
class RspecInsertContentCommand(sublime_plugin.TextCommand):
16+
def run(self, edit: sublime.Edit, text: str = ""):
17+
self.view.insert(edit, 0, text)

0 commit comments

Comments
 (0)