Ejemplo n.º 1
0
    def run(self):
        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("_spec", "", base_name)

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

            target_group = shared.other_group_in_pair(window)

            print("Current file: " + current_file)
            if re.search(re.compile(base_name + "_spec\.rb$"), current_file):
                self.open_project_file(source_matcher, window, target_group)
            elif re.search(re.compile(base_name + "\.rb$"), current_file):
                self.open_project_file(test_matcher, window, target_group)
            else:
                print("Current file is not valid for RSpec switch file!")
Ejemplo n.º 2
0
	def on_done(self, text):

		# create the module
		module = self.window.new_file()
		module.set_syntax_file('Packages/Ruby/Ruby.tmLanguage')
		module.set_name(translate(text, 'allcamel', 'underscores') + '.rb')
		module_template = "\n\
class " + text + "\n\
end"
		edit = module.begin_edit()
		module.insert(edit, 0, module_template)
		module.end_edit(edit)

		# create the spec
		spec = self.window.new_file()
		self.window.run_command('move_to_group', {'group': shared.other_group_in_pair(self.window)})
		spec.set_syntax_file('Packages/Ruby/Ruby.tmLanguage')
		spec.set_name(translate(text, 'allcamel', 'underscores') + '_spec.rb')
		spec_template = "require 'spec_helper'\n\
require '" + translate(text, 'allcamel', 'underscores') + "'\n\n\
describe " + text + " do\n\
\tit \"should do something\"\n\
end"
		edit = spec.begin_edit()
		spec.insert(edit, 0, spec_template)
		spec.end_edit(edit)
Ejemplo n.º 3
0
    def run(self):
        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('_spec', '', base_name)

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

            target_group = shared.other_group_in_pair(window)

            print("Current file: " + current_file)
            if re.search(re.compile(base_name + "_spec\.rb$"), current_file):
                self.open_project_file(source_matcher, window, target_group)
            elif re.search(re.compile(base_name + "\.rb$"), current_file):
                self.open_project_file(test_matcher, window, target_group)
            else:
                print("Current file is not valid for RSpec switch file!")
Ejemplo n.º 4
0
    def on_done(self, text):
        if not text:
            return

        *namespace, name = re.split(r"/|::", text.strip(" _/"))

        # create the module
        module = self.window.new_file()
        module.set_syntax_file("Packages/Ruby/Ruby.tmLanguage")
        module.set_name(snake_case(name) + ".rb")

        module.run_command("rspec_new_module", {"name": name, "namespace": namespace})

        # create the spec
        spec = self.window.new_file()
        self.window.run_command("move_to_group", {"group": other_group_in_pair(self.window)})
        spec.set_syntax_file("Packages/Ruby/Ruby.tmLanguage")
        spec.set_name(snake_case(name) + "_spec.rb")

        spec.run_command("rspec_new_spec", {"name": "::".join(namespace + [name])})
Ejemplo n.º 5
0
    def on_done(self, text):
        if not text: return

        *namespace, name = re.split(r'/|::', text.strip(' _/'))

        # create the module
        module = self.window.new_file()
        module.set_syntax_file('Packages/Ruby/Ruby.tmLanguage')
        module.set_name(snake_case(name) + '.rb')

        module.run_command('rspec_new_module', {
            'name': name,
            'namespace': namespace
        })

        # create the spec
        spec = self.window.new_file()
        self.window.run_command('move_to_group',
                                {'group': other_group_in_pair(self.window)})
        spec.set_syntax_file('Packages/Ruby/Ruby.tmLanguage')
        spec.set_name(snake_case(name) + '_spec.rb')

        spec.run_command('rspec_new_spec',
                         {'name': '::'.join(namespace + [name])})
Ejemplo n.º 6
0
    def on_done(self, text):

        # create the module
        module = self.window.new_file()
        module.set_syntax_file("Packages/Ruby/Ruby.tmLanguage")
        module.set_name(translate(text, "allcamel", "underscores") + ".rb")
        module_template = (
            "\n\
class "
            + text
            + "\n\
end"
        )
        edit = module.begin_edit()
        module.insert(edit, 0, module_template)
        module.end_edit(edit)

        # create the spec
        spec = self.window.new_file()
        self.window.run_command("move_to_group", {"group": shared.other_group_in_pair(self.window)})
        spec.set_syntax_file("Packages/Ruby/Ruby.tmLanguage")
        spec.set_name(translate(text, "allcamel", "underscores") + "_spec.rb")
        spec_template = (
            "require 'spec_helper'\n\
require '"
            + translate(text, "allcamel", "underscores")
            + "'\n\n\
describe "
            + text
            + ' do\n\
\tit "should do something"\n\
end'
        )
        edit = spec.begin_edit()
        spec.insert(edit, 0, spec_template)
        spec.end_edit(edit)
Ejemplo n.º 7
0
 def switch_to(self, file_path):
     group = shared.other_group_in_pair(self.window)
     file_view = self.window.open_file(file_path)
     self.window.run_command("move_to_group", { "group": group })
     print("Opened: " + file_path)
     return True
 def switch_to(self, file_path):
     group = shared.other_group_in_pair(self.window)
     file_view = self.window.open_file(file_path)
     self.window.run_command("move_to_group", {"group": group})
     print("Opened: " + file_path)
     return True