Swapping between JavaScript spec and implementation in RubyMine

February 13, 2014 Charles Hansen

When test driving your code, you inevitably end up switching between the tests and the implementation. In Rubymine, there is a handy command-shift-T shortcut for doing this with ruby files, but it does not work for javascript files. It isn’t too hard to add javascript functionality. The instructions are described below. They are very similar to my earlier post on launching a spec file in jasmine from Rubymine.

  1. Create the two files listed below, a shell script and a ruby file
  2. [gist id=8980243]

  3. Go to RubyMine -> Preferences -> External Tools -> +
  4. This should launch a new tool dialog. Fill in name, descriptions, etc
  5. For program, you should link the script you just created.
  6. For parameters, you should use “$FilePath$”
  7. Pay attention to working directory so that you can give the correct path to the ruby file in the shell script (line 8).
  8. Bind this external tool under keymaps (look for the name you just gave it). We replaced the original command-shift-T (the script works for Ruby too)
  9. Go to RubyMine -> Tools -> Create Command-Line Launcher and create a launcher in the same place as line 10 of the shell script (/usr/local/bin/mine is the default)

After these steps, you should be able to switch between spec files and implementation files. The whole setup relies on your spec folder layout to be the same as your implementation folder layout, so you may need to move some files around. In addition, it assumes that all of your spec files contain the string “_spec” in the name. If you use a different convention, you will need to reassign the `in_spec` regex on line 5 of the ruby file. Lastly, if you try to switch to a spec file that does not exist, we will attempt to create that file for you. This whole thing is a bit of a hack, let me know if you have any improvements. Enjoy your hopefully faster tdd experience.

About the Author


More Content by Charles Hansen
10 Key PaaS Statistics You Need To Know
10 Key PaaS Statistics You Need To Know

PaaS is a key ingredient to help businesses operate and compete more like the internet giants and innovator...

Creating the Digital Brain
Creating the Digital Brain

Oil spills from mining accidents can cost tens of billions per incident. The famed BP Oil spill in the Gulf...

Enter curious. Exit smarter.

Register Now