Created
March 21, 2017 19:14
-
-
Save psobot/3dc0e471c5e09412e34d7e931f38205e to your computer and use it in GitHub Desktop.
Rails "Copy Test Runner Command to Clipboard" for Sublime Text 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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