Ruby On Rails Lesson
Tests inside Sublime Text
If you’re using Sublime Text, there is a powerful set of helper commands to run tests directly insidetheeditor. To get them working, follow theinstructions for your platform at Sublime Text 2 Ruby
You may also want to follow the set-up instructions for Rails Tutorial Sublime Text at this time.20
After restarting Sublime Text, the RubyTest package supplies the following commands:
• Command-Shift-R: run a single test (if run on an it block) or group of tests (if run on a describe block)
• Command-Shift-E: run the last test(s)
• Command-Shift-T: run all the tests in current file
Because test suites can become quite slow even for relatively small projects, being able to run one test (or a small group of tests) at a time can be a huge win. Even a single test requires the same Rails environment overhead, of course, which is why these commands are perfectly complemented by Spork: Running a single test eliminates the overhead of running the entire test file, while running Spork eliminates the overhead of starting the test environment. Here is the sequence I recommend:
1. Start Spork in a terminal window.
2. Write a single test or small group of tests.
3. Run Command-Shift-R to verify that the test or test group is red.
4. Write the corresponding application code.
5. Run Command-Shift-E to run the same test/group again, verifying that it’s green.
6. Repeat steps 2–5 as necessary.
7. When reaching a natural stopping point (such as before a commit), run rspec spec/ at the command line to confirm that the entire test suite is still green.
Even with the ability to run tests inside of Sublime Text, I still sometimes prefer using Guard, but at this point my bread-and-butter TDD technique is the one