Skip to content

Instantly share code, notes, and snippets.

@psobot
Created March 21, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psobot/3dc0e471c5e09412e34d7e931f38205e to your computer and use it in GitHub Desktop.
Save psobot/3dc0e471c5e09412e34d7e931f38205e to your computer and use it in GitHub Desktop.
Rails "Copy Test Runner Command to Clipboard" for Sublime Text 2
[
{ "command": "get_single_test_run", "caption": "Copy Test Runner Command to Clipboard" },
{ "caption": "-", "id": "end" }
]
import sublime
import sublime_plugin
class GetSingleTestRunCommand(sublime_plugin.TextCommand):
EXTENSIONS = ['.rb']
LINE_MUST_CONTAIN = ["should"]
COMMAND = "bundle exec testrbl -I test"
def run(self, edit):
selection = self.view.sel()
fileName = self.view.file_name()
if selection and fileName:
startOfSelection = selection[0].begin()
lineNumberOfStartOfSelection = \
self.view.rowcol(startOfSelection)[0] + 1
expr = fileName + ":" + str(lineNumberOfStartOfSelection)
sublime.set_clipboard(self.COMMAND + " " + expr)
def is_enabled(self):
lineContent = self.view.substr(self.view.line(self.view.sel()[0]))
lineMatches = any(x in lineContent for x in self.LINE_MUST_CONTAIN)
return lineMatches
def is_visible(self):
if not self.view.file_name():
return False
if not len(self.view.file_name()):
return False
return any(
self.view.file_name().endswith(ext)
for ext in self.EXTENSIONS
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment