Using tmux for Pairing

With both of our tmux windows in a good working state as we left them in the previous section, let’s check out the Backbone.js code base. Run this command from either tmux terminal:

 
$ ​git clone [email protected]:documentcloud/backbone.git

Move into the newly created backbone directory and open the file test/model.js in any terminal-based editor, as you can see here:

 
$ ​cd backbone
 
$ ​vim test/model.js

This file contains some unit tests for Backbone’s model components. We can run these test by opening the test/index.html file in a browser. Split the tmux session horizontally by pressing Ctrl-b ", so that your window looks like the following figure.

images/tmux-backbone.png

Figure 8. The Backbone.js code in tmux

Then run this command in the new pane (you’ll have to skip this step if you’re using Vagrant, because it doesn’t have a browser):

 
$ ​open test/index.html

A browser will open and the JavaScript tests will run, as the following figure shows. There’s just one problem: our partner can’t see the browser because it’s not a part of the tmux session.

images/backbone-tests.png

Figure 9. Testing Backbone.js in a browser

There are many ways to share a browser, and some other ways of solving the problem without sharing a browser. The simplest solution is view-only screen sharing. If we are already using Skype or one of the similar tools we discussed in Chapter 1, Introduction to Pair Programming, then we can do this with the click of a button. View-only screen sharing is acceptable in this scenario because we aren’t actually controlling the browser. We’re only letting it run our tests. But screen sharing uses a lot of bandwidth just to watch some tests run. Wouldn’t it be better if we could run the tests in the tmux session? We can with a headless browser engine like PhantomJS.

PhantomJS is an implementation of WebKit that can be run from the terminal for jobs like running unit tests. On Mac OS X we can install it with brew by running this command:

 
$ ​brew install phantomjs

For Linux and Windows, download the binary for your platform from the official PhantomJS website and follow the installation instructions.[48] Regardless of the platform, we can run this command to test that the installation was successful:

 
$ ​phantomjs -v
 
1.9.0

Now return to our tmux session. In the bottom pane, run the command shown here:

 
$ ​phantomjs test/vendor/runner.js test/index.html
 
Took 363ms to run 755 tests. 755 passed, 0 failed.

The test/vendor/runner.js is a script for kicking off the unit tests in the index.html. Now both tmux users can watch them run.

Using terminal-based tools like tmux and PhantomJS is important when pair-programming because they require less bandwidth, have lower latency, and are usually easier to connect. But they won’t solve all of our problems. We have to be creative when pairing from the terminal, and sometimes we just need a graphical interface. In the coming chapters, we’ll explore some ways of doing this by sharing control of our screen.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.51.36