Davis W. Frank's blog
We had a client project, a Rails 2 app, that needed some cleanup around JavaScript and CSS management. They were using both Sprockets 1 and Jammit, as well as a bunch of plugins and gems to help make all this work together. They had a set of problems that the Rails 3.1 Asset Pipeline solved. But due to gem dependencies we couldn't go to Rails 3 yet.
How hard could it be to put Sprockets 2 and the Asset Pipeline into a Rails 2 app?
We powered through Movember this year with a bigger network, Webstache, and over 80 participants. Pivotal Labs - all four US offices - plus our friends at Square, Sharethrough, and Halogen all grew whiskers and helped raise money to end "dude cancer".
In 30 days, we met our goal of raising $20,000 for Livestrong and The Prostate Cancer Foundation and then some - the current tally is $23,318.
But that's not enough. We had Pivots who couldn't grow mustaches. And Pivots who had mustaches who didn't want to shave them. What are these Pivots to do?
Someone said, "But a Mohawk is like a mustache...FOR YOUR HEAD." Then there was much betting and cajoling and smack talk. In the end, Pivotal agreed to donate $500 to Movember for each Pivot that got a mohawk.
Which meant we needed to have Mohawk shaving parties in New York and San Francisco. Pivots in the Boulder and Denver offices, as well as a couple of remote Pivots did the same.
Total: 28 'hawks shaved (plus Gregg, the one with the green & purple one-day 'do merited a half-donation) and another big donation coming to Movember from their friends at Pivotal Labs. We may break $40K before the donations close.
Big thanks to my fellow Pivots for growing, donating, raising, and yes, shaving. And HUGE thanks to Pivotal Labs for tolerating all of this and making the big donation this year.
November First will begin like any other day. I'll wake up, I'll shower, I'll shave, I'll take the train to work, and then I'll code all day.
November Second will be a little different. I'll wake up, I'll shower, and I'll shave, and I'll take the train to work and code. But that shave will be a little shorter, skipping my upper lip. I'll continue ignoring one part of my face through the end of the month.
Why? Because it's Movember. And guys still get prostate and testicular cancer.
Last year during Movember, Pivotal Labs helped raise $10,000 of the $7.5M raised in the US for the Prostate Cancer Foundation and LIVESTRONG to help research and awareness of "dude cancer".
This year we want to double that amount. But we need your help.
We started a network at Movember called Webstache - a place where anyone in the web development community can start a team, or join a team, or just donate. Our friends at Square have joined the Pivotal teams from San Francisco, Boulder and New York. How about your company?
The mustache I'll be growing is sad. But not as sad as the fact that 1 in 6 men will be diagnosed with prostate cancer.
Your app now has mobile-friendly views. Do they have any Webkit-specific functionality that you want to test in-browser? Or rather, why are you testing your mobile views in desktop Firefox? Is it because Capybara/Selenium support for Webkit browsers was sketchy? Worry no more. Chrome 12, Capybara 1.0, and Selenium 2 are your new best friends.
So install Chrome, make sure your Gemfile has Capybara set to >= 1.0, bundle install and let's get configuring.
Update your SpecHelper
You have to tell Capybara that you want to use Selenium/Webdriver and Chrome. Put this in your spec_helper.rb file
Capybara.register_driver :selenium_chrome do |app| Capybara::Selenium::Driver.new(app, :browser => :chrome) end
Chrome & chromedriver
While there's been limited Selenium support in Chrome for a while, with release 12 there is an entirely new and complete automation interface to Chrome. To use it you need a platform-specifc chromedriver binary in order to connect Webdriver and Chrome. Download it, make sure it's executable, and put it on your path.
Chrome likes to update, so stay on the general release (if you can) to reduce update frequency. You can even take steps to prevent Chrome from updating, but I'll leave that as an exercise for the reader.
BOOM
That should be enough to get your Capybara specs to start using Chrome. You'll want to play with your setup and maybe only run some specs with this driver.
Caveats
Webdriver does not appear to support Safari. This may matter to you if you're using this setup to approximate Mobile Safari. But for the types of tests you're likely writing for Selenium it should be good enough. After all, every mobile Webkit build is slightly different.
While complete (in terms of browser features) and far faster than previous Selenium-Chrome pairings, it's still slow-ish - for example, typing isn't nearly as fast as Firefox. So you might not want to make this your default stack for your entire Rails app.
You might make it your only stack if you're testing a Webkit & JavaScript only framework, say an HP webOS application using Enyo.
But that's another post.
When writing nicely encapsulated code and you have a group of objects that share an interface (pick your favorite patterns), you often want to share your test code as well. If the system models financial accounts with credits and debits, and you make a change to the reconciliation code, you want to run a core set of specs against all cash, loan, and credit card account objects.
People ask how to do this in JavaScript on the Jasmine mailing list every so often.
So here's an example of "Shared Example Groups" in Jasmine.
Over the past two years we've worked on Tweed, our webOS Twitter client, we've learned a lot about mobile development, JavaScript techniques and of course the Twitter client space. But the landscape has changed a lot recently so we've been thinking a lot about Tweed.
Ask for Help
"Rubymine seems to have lost my RSpec stack trace? Spec from the command line is fine."
Check the run command & try reverting to the default options?
"What's our favorite 'copy to clipboard' code these days?"
Zero Clipboard - jQuery version - is the one that lets you bind the Flash code to any HTML element. That's the one you want.
"Can you use Jasmine to test a MongoDB map/reduce?"
Yes! It just uses JS objects, so you can unit test your code with Jasmine no problem. We recommend you add a couple of integration tests to make sure everything is connected properly.
Interesting Things
- The cmdparse gem has now been released under LGPL. This gem gets pulled in as a dependency for some other gems, but was GPL before. It should now be easier to deal with if you're license-wary
- Having memory leaks in your JavaScript? Try Leak Helper! It's a simple enumeration of objects off of
window, not catching objects inside closures, but it still helped a team find a set of circular references that were confounding the garbage collector.
Ask for Help
"How do you handle jQuery, new HTML5 elements, and IE6/7?"
Other than "I don't", how do you deal with building large article elements and then attach them to the DOM? It's icky since older IE's don't handle elements it doesn't know about. Do you have any suggestions?
"Are you using AuthSTMP on an app hosted at EngineYard? Is it working?"
Something changed and our configuration is no longer working. Not sure why.
Interesting Things
- RubyGems 1.4 is out. There are tips on how to upgrade nicely with RVM. But you might want to wait if you're using Ruby 1.9.
- Our friends at Irrational Design have launched Secret Goals and want you to share your good & horror stories about New Years' Resolutions.
We released this version of the gem yesterday. Included are two key fixes:
- Proper support of RSpec 2, and thus Rails 3
- Only require the JSON gem when it's used, thus not clobbering Rails's own patching of JSON
These means that the old instructions for using Jasmine with Rails 3 are now obsolete. Feel free to nuke the Jasmine gem from your repo and use this new version.
It's that time again. Pivots grow mustaches. We laugh, we itch, we cry, we talk about testosterone and whisker styling. Why do we do it? For Cancer research.
