Skip to content

Instantly share code, notes, and snippets.

@UltraInstinct05
Last active July 5, 2022 08:53
Show Gist options
  • Save UltraInstinct05/8a8fcbf63bb3f603c469032a22780bbc to your computer and use it in GitHub Desktop.
Save UltraInstinct05/8a8fcbf63bb3f603c469032a22780bbc to your computer and use it in GitHub Desktop.
Running tests using mouse bindings.
[
{ "button": "button3", "command": "execute_test_under_cursor" },
]
@UltraInstinct05
Copy link
Author

import sublime
import sublime_plugin

class ExecuteTestUnderCursorCommand(sublime_plugin.TextCommand):

    def run(self, edit, event):
        text_pos = self.view.window_to_text((event["x"], event["y"]))
        region = sublime.Region(text_pos, text_pos)
        line_number = self.view.rowcol(region.b)[0] + 1
        self.view.window().run_command("exec", {
            "shell_cmd": f"rspec {self.view.file_name()}:{line_number}"
        })

    def want_event(self):
        return True

This assumes that you want to run rspec <path_to_file>:<line_number> from the command line. The middle mouse button just helps in getting the line number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment