Spring is just around the corner, and it has been a beautiful week here in sunny NYC. We've learned a lot this week, as you'll see as we do the Round-up!
Ask For Help
- Kevin and I are having a heck of a time using Web Driver to drive an app that uses Google Maps. Whenever we click on or type into anything displayed on the map, the contents of the map (including the Google logo and the zoom control) move about 20 pixels up. Our tests seem to still work, it just looks like it's broken. Anyone else seen this or know what might cause it?
Interesting Things
Kevin and I discovered that Capybara's
page.execute_scriptdoesn't like to execute multiple statements. It really wants to evaluate a single expression. The upside of this is that it's really good at casting Javascript values into Ruby; it seems to work well with strings, numbers, and even arrays. If you really want to execute multiple statements, you can do this:page.execute_script <<-JS (function(){ statement1(); statement2(); return someValue; })() JSTodd found out the hard way that Ruby's
String#sprintf(also seen as theString#%) will cast your string numbers to octal if you're not careful. Behold:>> "%d" % "010" => "8" >> "%d" % "08" ArgumentError: invalid value for Integer: "08" from (irb):2:in `%' from (irb):2Make sure you don't feed
sprintfa string number that starts with a0unless you mean it to be octal.Rachel tells us that there's an upcoming Rails workshop for women in NYC. Rumor has it that Pivotal's own Sarah Mei is behind it. She's been known to do such things before. Details as they become available.
Pat's improv show is tonight! Check him out at the Magnet Theater.
Help:
- Testing blocks. If you have a block and you want to spy on the internals as it executes, what do you do? Suggestions were:
- Have each method called internally throw a symbol and check for that.
- Turn it into a proc, and set expectations on that.
- Stub the methods being called internally and set expectations on those.
- pass the block to a spy object.
Other suggestions welcome. The project is using rr, which apparently can't do this last option, though that would be ideal.
- Routes in Rails are case-sensitive? /products/1/edit and /Products/1/edit don't both resolve to the same place (unless you specify in routes.rb). Rumor has it that the RFC for URIs says that the path portion of a URL is case-sensitive, as opposed to the case-insensitive domain name.
If anyone wants to read through that document and confirm...feel free.
Yesterday we had Mat Brown of Patch.com giving us a presentation on his Sunspot gem for easily adding full-text search to a Rails application via Solr.
Mat walked us through the steps for adding Sunspot to a Rails application, talked through some of the production deployment concerns of Solr and illustrated some of the new features of Solr 1.4 such as master/slave replication and sharding that make it worth a look for full-text search.
Most of our tech talks are open to the public. If you're interested in joining us for presentations like this please join our mailing list.
That's it. I'm done with TextMate. It hasn't been updated in over 2 years, either for essential functionality (replace in path) or performance fixes (searching through log files) or UI issues (how many boxes must you click to enable autosave?) or bug fixes. Every few months the author pokes his head up and says "I'm working on TextMate 3.0!" and then disappears again, happily accepting new license fees into his PayPal account.
I've just been bitten twice in two weeks by a bug that caused not just data loss, but data mangling in a way that was very difficult to fix. Here's the rough steps to reproduce:
- Edit some files in TextMate
- Leave TextMate running in the foreground
- Switch to console and "git pull" in the latest code from your workmates
- Run a search-and-replace that edits a file that was changed (by someone else) during the merge
- Save that edit
You'll see (with "git diff") that your version of the file has your new post-merge changes... but it also has reverted your buddy's changes from the merge. It's like you decided that those changes were no good and reverted them yourself and then added your own.
If you fail to notice this before checking in, you will totally hose your version control... but just for that one file. You can't just revert a whole commit... you'll have to step through change by change to figure out which change was theirs, which change was yours, and which change looks like it was yours but was actually an inadvertent revert of theirs!
I can't work under these conditions. I'm switching to RubyMine today. See http://bjclark.me/2010/03/10/rubymine-a-love-story/ for why.
P.S. I just found a bug report for this dated 2008-04-02. That's just about 2 years ago for a critical data-losing bug. Woot.
Help
- Latest Rails book? One pivot is coming back to Rails after several years away. Recommendations: The Rails Way, Rails Guides, Railscasts.
Interesting
- The on302 callback is a myth! One team discovered that if you set a 302 (redirect) callback for an AJAX call, like in Prototype, the redirect is followed by the browser and the callback is never called. Suggestions: hack the library so that if the response URL doesn't equal the request URL, call the on302. Or do that in your application Javascript.
Help
One team is starting to use Sunspot and is curious about testing strategies. Sunspot provides a method that stubs out the backend, but search blocks aren't executed, so it's hard to test actual searching.
Objective C needs a BDD framework. How does Xcode magically know about OCunit? We need to hook in there to have a usable framework.
Interesting
- Mountain West Ruby Conf was awesome.
Spring is in the air here in sunny NYC! Well, it was sunny for a bit. Now it's turned into that classic film-noir drizzle. That's authentic New York weather outside our window as we do the Round Up!
Ask for Help
I asked, "In Jasmine, how do you spy on a constructor?" Suppose you have a constructor called
Widget. SayingspyOn(window, "Widget")swaps out the realWidgetfunction with a spy. The realWidgetimplementation takes its prototype with it, which means that Widgets created while the constructor is spied on don't get the methods aWidgetwould get. That's true even when you spy withspyOn(window, "Widget").andCallThrough().Also, there doesn't seem to be a way to stub out object construction and return an object of your choosing. In Rspec in Ruby you can say,
Widget.should_receive(:new).and_return(my_fake_widget)
because
.newis a class method. But in Javascript,newis a keyword which always creates a new object. I'm guessing there's no good way around this, but if there is one, we could really use it.Update: This is, as it turns out, entirely incorrect. Jasmine's
.andReturn()does let you stub constructors properly. I still have no idea how this works. See the comments for more discussion.
Interesting Stuff
Todd notifies us that in ActiveRecord, dynamic finders with too-few arguments fail silently. That is, if you say,
Person.find_by_first_name_and_last_name_and_email("Todd", "Persen")
and fail to specify a value for
email, the value is taken to benil. That means that the finder will look for someone named "Todd Persen" with anilemail address. You might have meant that. More likely, you made a mistake. AR should probably check the number of arguments it's given against the number of columns in the finder name.You already know that Pivotal does real Extreme Programming. But did you know that we have...Extreme Breakfast?

Helps
Q: How can I plot thousands of points on a Google Map without said map being undraggable? A: It may make sense to use Google's HeatMap API after the number of plotted points exceeds 500. Other strategies are discussed here: Handling Large Amounts of Markers in Google Maps
Interesting
Using ReCSS with Sass. If you happen to be using SASS you can still make use of awesome ReCSS bookmarklets (including one by Pivotal's own Erik Hanson) by using the compass command line tool and watching your project for changes. Totally rad!
Ruby Enterprise Edition Is awesome, if you use the garbage collection tweaks. One team installed it and saw a 50% savings in their test suite running times -- over 15 minutes! Combined with parallel spec it can be a real winner. If you're on Leopard, you may need to install the version from Oct 2009, as the latest fails with a Marshall.load error on install. 2 legit!
All your RubyMine problems can be fixed! By reverting to RubyMine 1.1.1. At least if your problems are: inconsistent functionality with the merge tool, and RubyMine occasionally refusing to recognize spec files correctly. That's def!
Spring Forward this Sunday to save the daylight, and terrorize the programmers. Thanks a lot, farmers-slash-botanists. WORD Y'ALL. I'M OUT.
Making truly awesome stuff is hard. Pivot Carl Coryell-Martin proposes we identify common physiological responses and condense their design solutions into a pattern language. He presents a draft set of patterns in the context of crafting an iPhone app.
See all our talks at http://pivotallabs.com/talks
Interesting Things
A few projects are using parallel_test to speed up their tests/specs. One project has had the best results by running one less parallel spec than the number of cores on the machine, unless of course you only have one core.
Another team discovered an odd bug in RubyMine where they could not click-through "require spec" or run specs if their project had code in vendor/plugins that extended ActiveRecord::Base. Here is the RubyMine ticket they filed.
Finally, it looks like a Linux machine running Ruby 1.8.6 patch 287 had rounding errors when using the ActiveSupport helpers for 2.days.ago. They fixed the issue by upgrading to Ruby 1.8.7







