Davis W. Frank's blog



Davis W. FrankDavis W. Frank
Giving Rails 2 the Asset Pipeline
edit Posted by Davis W. Frank on Thursday December 29, 2011 at 02:19PM

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?

Davis W. FrankDavis W. Frank
Capybara, Selenium, Webkit and your Mobile Site
edit Posted by Davis W. Frank on Saturday July 16, 2011 at 11:12AM

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.

Davis W. FrankDavis W. Frank
Jasmine Gem 1.0.1.1 Released
edit Posted by Davis W. Frank on Wednesday November 10, 2010 at 01:17PM

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.

Davis W. FrankDavis W. Frank
Jasmine in Rails 3
edit Posted by Davis W. Frank on Thursday September 23, 2010 at 11:47AM

UPDATE: We've released a new version of the Jasmine Gem and these steps are no longer required. Please see the announcement here


Bad news, everyone! At the moment, the released Jasmine gem is not yet Rails 3 compatible.

Good news, everyone! We now have a short term workaround while we deal with the work needed to work seamlessly with Rails 3.

Davis W. FrankDavis W. Frank
Jasmine 1.0 Released
edit Posted by Davis W. Frank on Tuesday September 14, 2010 at 01:49PM

Pivotal Labs and the Jasmine team are pleased to announce the 1.0 release of Jasmine, our JavaScript BDD framework.

This release is largely about stabilization. We've fixed some bugs, stabilized our API, and improved support for JRuby and Ruby 1.9. There are several deprecations (especially around asynchronous 'waits' blocks and some matchers) to go along with the fixes and features. See the release notes for full details.

This release is available in standalone and Ruby gem versions.

Our upcoming priorities include improving the documentation, properly supporting Rails 3 and RSpec 2 and a number of other environments, and looking at all of your pull requests and issue reports. Jasmine's backlog lives in Pivotal Tracker.

Big thanks to the Jasmine community for the pull requests; the majority of changes between 0.11.1 and 1.0 are based on user-submitted patches.

See you on the mailing list and make sure to follow us on Twitter: @jasminebdd...

Davis W. FrankDavis W. Frank
Standup 2010.06.14: as_if Edition
edit Posted by Davis W. Frank on Monday June 14, 2010 at 06:26PM

Interesting Things

If you are overriding to_json in any of your Rails models you should read Jonathan Julian's blog post which explains the purpose of as_json vs to_json.

Choice quote:

Enter ActiveSupport 2.3.3. Now the creation of the json is separate from therendering of the json. as_json is used to create the structure of the JSON as a Hash, and the rendering of that hash into a JSON string is left up to ActiveSupport::json.encode. You should never use to_json to create a representation, only to consume the representation.

as_json is also easier to test because it returns a Ruby Hash instead of a String.

Davis W. FrankDavis W. Frank
What's so funny 'bout pseudo-classical inheritance (in JavaScript)?
edit Posted by Davis W. Frank on Monday February 15, 2010 at 05:17PM

Our customers are asking for richer interfaces and user experiences. And so we - and by "we" I mean the Rails development community - are writing more and more JavaScript. We've gone from ignoring JS (using RJS server-side) to rendering JSON and writing our own jQuery plugins.

But in this transition some of us left our objects & design patterns on the server. Just because you're writing a click handler in JavaScript doesn't mean it couldn't, or shouldn't, be a method on an object.

Davis W. FrankDavis W. Frank
Standup 2010.01.21: Questionable Latin Edition
edit Posted by Davis W. Frank on Thursday January 21, 2010 at 01:34PM

Interesting Things

  • Caveat Experior: Pivot Mike found a bug in Webrat in Selenium mode when using #click_link. He filed a ticket at Lighthouse.
  • Caveat Coracinatus: Attention to those "Riding the Toad" (I didn't make this up - it's on Hoptoad's homepage): the Hoptoad Notifier gem that was released on Jan 20, v2.1.1, is missing a file. Make sure to update to the latest version, v2.1.2 in order for this gem to work. You should be on the latest gem anyway because there's a deprecation in the session code that will stop working in February. If you have a site that's not actively being developed you will need to update the gem & redeploy your app in order to continue to receive exception notifications.

Davis W. FrankDavis W. Frank
Follow-ups from my RailsConf talk
edit Posted by Davis W. Frank on Wednesday May 06, 2009 at 04:23PM

First, thanks to everyone who came - especially those who laughed at all the right spots. If I didn't get to your question, I'm here through Thursday afternoon.

There were a couple of questions during the talk and lots after the talk about how to deal with remote pairs. Since it's RailsConf and most folks are on MacOS, ScreenSharing.app came up.

Davis W. FrankDavis W. Frank
More on my RailsConf talk
edit Posted by Davis W. Frank on Thursday March 26, 2009 at 06:23PM

As I've mentioned before, I'll be giving a talk at RailsConf on how I "got more agile" once I was able to practice every day. The goal is for my story to help you in your career, telling some good stories in the process.

To celebrate/entice you to come to RailsConf & my talk, (Tuesday, 2:50pm, Ballroom A) and to thank those of you who contributed your own tips, I have two things for you.

First is a promise of Pivotal Labs swag (content TBD) to anyone who submitted a tip & to the first five comment authors who claim it below and identify themselves at the actual session - no sneaking off to Scott's Advanced Git talk.

Second, for everyone, is a RailsConf discount of 15% in case you haven't registered yet. When you register, use the promo code RC09FOS. Note that as of yesterday, the Hilton's room rate has dropped to $99 a night. w00t!

Other articles: