Capycorder is an extension for Google Chrome. Once enabled, it first records unser interactions with forms and links across page loads, allows to define matchers by selecting elements or highlighting text and finally generates simple request specs. These code snippets are then copied into the clipboard for use in the actual specs.
Creating specs for an existing application is not all that much fun, but I wanted to have a good test coverage before moving onto new features and refactoring. Since PR! seemed to behave okay in development (and beta production), simply "recording" user interaction and automatically producing some of the needed specs or seemed like a logical thing to do.
Enable the extension with the first click on the extension icon next to the browser bar. You are prompted to provide an optional name for the test — usually an expectation in the suggested
should do something -format.
A second click enables the action recorder. Every interaction with forms and links will be recorder.
Once all necessary actions have been recorder, click the extension icon again to enable the matchers recorder. Clicking DOM elements and selecting text by highlighting it will record expectations on what the current page should contain.
When you're done, hit the extension icon once more to generate the specs, to wrap recorded actions into form scopes and copy everything into the clipboard.
The output looks something like this:
it 'should log the user in' do visit('/login') do within('login') do fill_in('email', :with => 'email@example.com') fill_in('password', :with => 'secret') check('remember_me') click_button('submit') end page.should have_content('Account') end
Capycorder is built using Coffeescript and a dash of HTML/CSS for the GUI. I’ve added a small build script written in Ruby (using Thor and Nokogiri) which takes care of compiling, copying and packaging the extension files.
A word about BDD
Some might feel that this helper and what it does goes against the "tests first" philosophy and may support bad habbits.
Test driven development is great in my opinion and should definitely be prefered over adding tests after the fact. But we all know, that realisticly sometimes testing just doesn't happen at all or that projects come with a few unit tests only.
I'm hoping that in this case, a small tool like Capycorder can lower the barrier and help to get some specs up and running a tad faster.