Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Williams committed Jul 9, 2011
0 parents commit 0efb411
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{ "keys": ["super+alt+b"],
"command": "exec",
"args": {"cmd": ["rake", "spec"]},
"file_regex": "# ([A-Za-z0-9_./ ]+rb):([0-9]+)",
"working_dir": "${folder}"
},

{ "keys": ["super+alt+period"], "command": "open_rspec_file", "args": {"option": "test_and_source"} },
{ "keys": ["super+period"], "command": "open_rspec_file", "args": {"option": "next"} },
{ "keys": ["super+alt+s"], "command": "open_rspec_file", "args": {"option": "source"} },
{ "keys": ["super+alt+t"], "command": "open_rspec_file", "args": {"option": "test"} }
]
3 changes: 3 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "keys": ["alt+f7"], "command": "exec", "args": {"cmd": ["rake", "spec"], "file_regex": "# ([A-Za-z0-9_./ ]+rb):([0-9]+)"} }
]
63 changes: 63 additions & 0 deletions OpenRSpecFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sublime
import sublime_plugin
import re, inspect, os

class OpenRspecFileCommand(sublime_plugin.WindowCommand):

def run(self, option):
if not self.window.active_view():
return

self.views = []
window = self.window
current_file_path = self.window.active_view().file_name()

if re.search(r"\w+\.rb$", current_file_path):

current_file = re.search(r"([\w\.]+)$", current_file_path).group(1)
base_name = re.search(r"(\w+)\.(\w+)$", current_file).group(1)
base_name = re.sub('_spef.rb', '', base_name)

source_matcher = re.compile("[/\\\\]" + base_name + "\.rb$")
test_matcher = re.compile("[/\\\\]" + base_name + "_spec\.rb$")

print(current_file)

if option == 'next':
print "Current file: " + current_file
if re.search(re.compile(base_name + "_spec\.rb$"), current_file):
self.open_project_file(source_matcher, window)
elif re.search(re.compile(base_name + "\.rb$"), current_file):
self.open_project_file(test_matcher, window)
else:
print "Current file is not valid for RSpec switch file!"
elif option == 'source':
self.open_project_file(source_matcher, window)
elif option == 'test':
self.open_project_file(test_matcher, window)
elif option == 'test_and_source':
window.run_command('set_layout', {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
})
self.open_project_file(test_matcher, window, 0)
self.open_project_file(source_matcher, window, 1)

for v in self.views:
window.focus_view(v)

def open_project_file(self, file_matcher, window, auto_set_view=-1):
for root, dirs, files in os.walk(window.folders()[0]):
for f in files:
if re.search(r"\.rb$", f):
cur_file = os.path.join(root, f)
print "Assessing: " + cur_file
if file_matcher.search(cur_file):
file_view = window.open_file(os.path.join(root, f))
if auto_set_view >= 0: # don't set the view unless specified
window.run_command('move_to_group', {'group': auto_set_view})
self.views.append(file_view)
print("Opened: " + f)
return
print("No matching files!")
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Description
===========
[RSpec](http://rspec.info/) is a BDD (Behavioral-Driven Development) testing framework for Ruby. This package adds support to Sublime Text 2 for testing Ruby applications wioth RSpec.

Package Installation
====================
Bring up a command line in the Packages/ folder of your Sublime user folder, and execute the following:
> git clone git://github.com/SublimeText/RSpec.git
When you launch Sublime Text 2, it will pick up the contents of this package so that you can consume the goodness that it provides.

Features
========
* RSpec.sublime-build for executing unit tests for the active module via the S2 *Build* command
* You must assign the builder for your project to 'Ceedling'
6 changes: 6 additions & 0 deletions RSpec.sublime-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cmd": ["rspec", "$file"],
"file_regex": "# ([A-Za-z0-9_./ ]+rb):([0-9]+)",
"working_dir": "${folder}",
"selector": "source.ruby"
}

0 comments on commit 0efb411

Please sign in to comment.