Skip to content

Commit

Permalink
Fall back to create spec when not found
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegSmelov committed Dec 12, 2016
1 parent 2cccf26 commit c26d902
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions rspec/switch_between_code_and_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from rspec.files.spec import SpecFile
from rspec.files.source import SourceFile
from rspec.rspec_print import rspec_print
from create_spec_file import CreateSpecFile
import os
import sublime

class SwitchBetweenCodeAndTest(object):
def __init__(self, context):
Expand All @@ -16,9 +18,20 @@ def run(self):

if files:
OpenFile(self.context.window(), files).run()
elif self._fall_back_to_create_spec():
CreateSpecFile(self.context).run()
else:
rspec_print("No files found, searched for {0}".format(self._file_base_name()))

def _fall_back_to_create_spec(self):
if self.context.is_test_file(): return False

return sublime.ok_cancel_dialog(
"Spec file not found.\n"
"Do you want to create it?",
ok_title = "Create"
)

def _direct_match(self):
direct_match = self.context.from_settings("switch_code_test_immediately_on_direct_match")
return direct_match and self._files_by_path()
Expand Down

0 comments on commit c26d902

Please sign in to comment.