Skip to content

Commit

Permalink
Add command for listing tests/specs
Browse files Browse the repository at this point in the history
  • Loading branch information
noklesta committed Jun 30, 2012
1 parent 1c2c546 commit 2f43bdd
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"caption": "Simple Rails Navigator: List views",
"command": "list_rails_views"
},
{
"caption": "Simple Rails Navigator: List tests/specs",
"command": "list_rails_tests"
},
{
"caption": "Simple Rails Navigator: List javascript files",
"command": "list_rails_javascripts"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ project file under a top-level "settings" key. An example of the latter:

## Credits

- Inspiration from Luqman Amjad's Rails Related Files plugin for ST2.
- Inspiration from Luqman Amjad's Rails Related Files plugin for ST2 and from Tim Pope's rails.vim plugin for Vim
(which contains sooo much more functionality than this one, of course :-)
- Python version of the Rails inflector: <https://bitbucket.org/ixmatus/inflector>
- Contains a modified version of a small code snippet from the Git package for ST2.

Expand Down
32 changes: 32 additions & 0 deletions SublimeRailsNav.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,38 @@ def is_listing_current_file_group(self, current_file):
return 'app/views' in current_file


class ListRailsTestsCommand(RailsCommandBase):
def run(self):
self.root = self.rails_root()
if os.path.isdir(os.path.join(self.root, 'spec')):
# RSpec seems to be installed, so ignore the 'test' dir and search for specs
self.test_type = 'spec'
self.model_test_dir = os.path.join('spec', 'models')
self.controller_test_dir = os.path.join('spec', 'controllers')
else:
# No RSpec, so use the standard 'test' dir
self.test_type = 'test'
self.model_test_dir = os.path.join('test', 'unit')
self.controller_test_dir = os.path.join('test', 'functional')

self.show_files([[self.test_type]])

def construct_related_file_name(self, current_file):
if self.MODEL_SEGMENT in current_file:
related_file = re.sub(self.MODEL_SEGMENT, self.model_test_dir, current_file)
related_file = re.sub(r'(\.\w+)$', '_%s\g<1>' % self.test_type, related_file)
return related_file
elif self.CONTROLLER_SEGMENT in current_file:
related_file = re.sub(self.CONTROLLER_SEGMENT, self.controller_test_dir, current_file)
related_file = re.sub(r'(\.\w+)$', '_%s\g<1>' % self.test_type, related_file)
return related_file
else:
return None

def is_listing_current_file_group(self, current_file):
return os.path.join(self.root, self.test_type) in current_file


class ListRailsJavascriptsCommand(RailsCommandBase):
def run(self):
dirs = self.get_setting('javascript_locations')
Expand Down

0 comments on commit 2f43bdd

Please sign in to comment.