Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker
Davis W. Frank

Capybara, Selenium, Webkit and your Mobile Site

Davis W. Frank
Saturday, July 16, 2011

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.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Matthew Kocher

Guiderails: our Rails 3 templates

Matthew Kocher
Monday, June 6, 2011

One of our goals for the first day a project starts at Pivotal is to deliver something the customer can see working. One of the ways we accomplish this is making sure getting up and running with all of our (more) reasonable defaults only takes a few minutes. We’ve been using guiderails for this internally for a while now, and soft launched it last week. I’m happy to give a full introduction today.

Currently Guiderails supports choosing:

  • Mysql or Postgres
  • RR or Mocha
  • Webrat with Saucelabs support
  • Cucumber with Capybara (no suacelabs support)
  • SASS (with HAML)

And includes by default:

  • A ci_build.sh script for running your project in CI.
  • A local git repo
  • An rvmrc
  • Bundler, auto-tagger, JSON, Heroku, rspec-rails, Jasmine, and Headless gems (in the global or development groups)
  • Jasmine initialized for JavaScript testing
  • Respec installed
  • Some testing related rake tasks

For more details, check it out on github at https://github.com/pivotal/guiderails.

Guiderails is a great way to get going quickly on a project. Many thanks to the Pivots that contributed.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Ken Mayer

[Standup][sf] 5/20/2011 DVORAK? I hardly knew her!

Ken Mayer
Friday, May 20, 2011

Helps

“Can I use after_initialize to set up nested associations for use with Controller#new actions?”

Not recommended. It is better to write a custom #new_for_form method in your model that pre-populates your instance variables with the 1 or more nested objects. That way you can test drive it, too.

“DelayedJob YAML parser in Ruby 1.9 is having issues.”

The compiled-in psych library has issues, use the tenderlove/psych gem instead. You have to use Bundler, however. Invoking require "psych" will use the compiled-in version.

“RubyMine is not honoring a DVORAK keyboard layout properly (it is mapping keyboard shortcuts to the QWERTY layout)”

Use a hardware dongle.

“Jenkins is trying to kill off Postgres?”

Does anyone have Jenkins CI working with Postgres? It seems that after a build is complete, some java deep down inside Hudson is trying to parse the process table, and it is choking on the Postgres entries. (Postgres re-writes ARGV[0] to display status info, you can’t rely on it be the original command line.) It remains a mystery why Jenkins would even need this information.

“Is anyone using Chrome in CI? The windows are transparent”

Sounds pretty. Odd, but pretty.

Interesting

“brew info … is your friend”

Can’t remember how to start or stop a daemon under OS X? If you installed it via Homebrew you are in luck:

brew info <foo>

Will print out the original install instructions, including exact lines to pass to launchctl(1), etc.

“More ‘special’ keywords to avoid in your models: target and source“

ActiveRecord Polymorphic Associations use a method called target internally. If you have an attribute in your model / database, also called target, then strange things will happen.

“Paperclip’s <model>.attachment.exists? is slow; it goes out to S3 (or whatever the store is)”

And it happens in strange places. Be warned. Or mock out your network calls.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Ken Mayer

[Standup][sf] 2011-05-18 Dropsick

Ken Mayer
Wednesday, May 18, 2011

Help

  • rake db:drop deliberately ignores exceptions and does not return a non-zero error code to the shell. A pivot has a need to know that the database was, indeed dropped, without errors. How to do it? Don’t rewrite the ‘db:drop’ task; it is a messy 40+ line task that needs to connect to database adapters, etc. You could run rake db:version — it will return an exit(1) if there’s no database there.

  • Can Rails scaffold handle nested resources properly? “No” was the almost instant, if not prescient response. Use one of the alternatives.

Interesting

  • Alex Young’s blog post, “Bulletproof Deployment: Put Down the Pickaxe” describes a 90-line shell script that does most of what Capistrano or Vlad does.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

Visit to Olin College

Pivotal Labs
Thursday, February 3, 2011

Visiting Olin

Today, Josh Knowles, Grant Hutchins, and I visited Franklin W. Olin College of Engineering in Needham, MA to talk to Prof. Mark L. Chang’s amazing new dotcom course. We talked about agile development, and more specifically how Pivotal does agile and why. We went through an example of test-driven development for a simple Rails app, and had a miniature inception for a fictitious product.

Some students asked for some resources, particularly for documentation, so I put together a collection of resources for anyone looking to pick up agile, TDD and Ruby on Rails. This is intentionally not an exhaustive list. I wanted to include the bare minimum for getting started on each topic as a jumping off point and include further references at the end.

Agile Development

Agile the Pivotal Way

A talk by Ian MacFarland, also available on iTunes. video and audio
What agile development means for Pivotal, with a healthy dose of how much fun it is to work here.

Pivotal Tracker

You can think of Pivotal Tracker as a digital card wall. It’s our most indispensable project tool.

Test-Driven Development

RSpec presentation

This talk by Kerry Buckley is probably the best RSpec overview and tutorial I’ve seen. Read this and follow along with the code and you will know more than just the basics of how TDD with RSpec works.

Robolectric

The Pivotal Labs TDD framework for Android development with a great Getting Started Guide and JavaDoc.

Source Control

Git Immersion

A great interactive tutorial on git.

Ruby

Ruby Koans

Learn Ruby through test-driven development. This tutorial covers a huge number of features of the Ruby language in a fun and interactive way.

Rails

Rails for Zombies

Includes video tutorials and interactive exercises that go over the core concepts of Rails.

Popular gems

We commonly use the following gems on Pivotal projects:

  • devise for authentication — check out their README and Wiki for documentation
  • cancan for role-based authorization — again, check the README and wiki for documentation
  • rspec-rails for TDD — see Wiki for installation, see above RSpec presentation for how to use it
  • cucumber-rails for BDD and integration testing — see README for installation, this Railscast for an introduction
  • paperclip for file attachment and storage — see README for documentation
  • will_paginate for index pagination (ie: “Showing results for Page 1 of 30″) — check out the README
  • jquery-rails for Javascript — to begin with, Prototype may be enough for you, but if you’re comfortable with jQuery or want to give it a try, follow the README to install jQuery and remove Prototype from your Rails project

Further Reading

  • RailsAPI.com
  • Agile Development with Rails
  • Programming Ruby
  • The RSpec Book
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Nate Clark

revealing the ActionController callback filter chain

Nate Clark
Tuesday, February 1, 2011

Sometimes your controllers get so full of before_filters, after_filters, and around_filters that it’s hard to figure out what order these callbacks are actually executing in. A couple of times recently, I’ve run into some tricky bugs that ended up being related to callbacks running too soon or too late.

Due to some fancy-pants metaprogramming in AbstractController::Callbacks, it’s hard to see what’s going on.

In Rails 3, send this to Rails.logger.debug or puts from inside your controller to see the ordered filter callback chain:

_process_action_callbacks.map(&:filter)
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Tyler Schultz

Standup 2010-12-10: Flash <embed> Scaling, Heroku + Amazon RDS, Overriding Default Scope

Tyler Schultz
Friday, December 10, 2010

Help

  • Some pivots are having trouble with a flash embed tag’s scale attribute. The desired behavior is that the movie scale to fit the size of the element. According to documentation, this should just work. The flash content will not scale, instead the content is getting cropped.

  • Anyone have experience using Amazon RDS with Heroku?

    Several projects at Pivotal have used this combination with great success.

Interesting

  • A project had some intermittently slow queries. The problem was traced back to some large strings in one of the columns. The team solved this problem by overriding the default scope, and only selecting the expensive column when needed.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Pivotal Labs

RSpec 2 Gotcha with polymorphic_path

Pivotal Labs
Wednesday, December 8, 2010

A quick gotcha we ran into when using polymorphic path and rspec2 today.

In a controller test we had an assertion:

response.should redirect_to(polymorphic_path(@some_object))

Which resulted in the following error

Failure/Error: Unable to find matching line from backtrace stack level too deep
# ~/.rvm/gems/ruby-1.9.2-p0@gemset/gems/rspec-expectations-2.1.0/lib/rspec/matchers/method_missing.rb:4

It turns out polymorphic path is not available in the controller test (but the usual object_path method is). As to why this throws a stack level too deep and not a method undefined looks like potentially another bug in rspec but the solution seemed to be to do the following in our spec_helper.b for Rails 3:

include Rails.application.routes.url_helpers

For Rails 2.x you’ll want to use:

include ActionController::UrlWriter

I’ve opened an issue for this on github as well https://github.com/rspec/rspec-expectations/issues/issue/46

  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Tyler Schultz

Standup 12/07/2010: bundler & rspec 2 & rails 3 – I go out of my head And I just can't get enough, I just can't get…

Tyler Schultz
Tuesday, December 7, 2010

Interesting:

  • Tests won’t run if rspec is included in the test group. rspec must be included in the development group, or both. When a test run is started the RAILS_ENV is development. After some initialization the RAILS_ENV is changed to test – a point at which the Gemfile has already been evaluated.
  • 0 Shares
  • Share on Facebook
  • Share on Twitter
Ken Mayer

rails 3.0.2 + jasmine 1.0.1.1 + json_pure == dll_hell.rb

Ken Mayer
Tuesday, November 23, 2010

The 3.0.2 update to rails made a change in active support that creates an interference pattern failure in the jasmine-gem. Not jasmine, itself, mind you, just the standalone server that runs the jasmine tests, and not the server, but just the report runner. Thus, your tests are all green, but the jasmine suite fails anyway. You might see this error:

undefined method `merge' for #<JSON::Pure::Generator::State:0x102181890> (NoMethodError)

The selenium driver inside the jasmine gem is loadingjson_pureunless it can find an already loaded JSON class. json_pure was hacked by rails for other reasons, but it breaks JSON.generate. Madness ensues.

To fix this, you need to use something other than json_pure, at least in your test suite. The fix, fortunately, is pretty simple. Add the following line to your Gemfile

gem "json", "1.4.6"

This will load the json gem built with native extensions. The version number is not necessary to fix this problem, but we try to lock down versions as a standard practice.

This was maddeningly painful to pinpoint. I’m not sure if there’s a long term solution to the problem either. You need a JSON library, but so do many others. Monkey patching the class seems really handy, but is prone to break behaviors.

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

Topics

  • agile (778)
  • rails (113)
  • testing (86)
  • ruby (83)
  • ruby on rails (70)
  • jobs (62)
  • javascript (54)
  • techtalk (44)
  • rspec (38)
  • activerecord (29)
  • productivity (29)
  • gogaruco (29)
  • ironblogger (29)
  • git (28)
  • nyc (27)
  • rubymine (25)
  • mobile (22)
  • bloggerdome (20)
  • cucumber (20)
  • process (19)
  • pivotal tracker (19)
  • jasmine (19)
  • design (18)
  • ios (18)
  • webos (17)
  • objective-c (17)
  • android (16)
  • palm (16)
  • "soft" ware (16)
  • fun (15)
  • tracker ecosystem (15)
  • ci (15)
  • cedar (15)
  • rails3 (14)
  • performance (14)
  • bdd (14)
  • gem (13)
  • selenium (12)
  • css (12)
  • goruco (12)
  • bundler (12)
  • tdd (12)
  • meetup (11)
  • railsconf (11)
  • nyc-standup (11)
  • capybara (10)
  • mac (10)
  • mojo (10)
  • chef (10)
  • rubygems (9)
Subscribe to rails Feed
  1. ←
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5
  7. 6
  8. 7
  9. 8
  10. 9
  11. 10
  12. 11
  13. 12
  14. →
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >