A Pivot noted a facepalm + headdesk moment when debugging an issue whose cause turned out to be related to two adjacent string literals being auto-concatenated by Ruby’s parser.
>> "foo" "bar"
In this case, a missing comma in a method call went undetected because of this language characteristic. Whether or not this follows the principle of least surprise is an exercise left up to the reader.
.. in 1.8.6 you can’t use a block as a parameter of a block.
Another pair noted that exceptions with Sunspot can cause wider failures on a site than just those that touch Solr. The symptom on this project was that if Solr was inaccessible for any reason every page on the site would throw an error. Their fix was to use Sunspot’s SessionProxy to wrap methods with some exception handling love.
Lastly, GoRuCo — the Gotham Ruby Conference — will be held on May 22nd at Pace University’s downtown campus. The roster of talks is up and registration is open for business.
Does anybody have any good techniques for dealing with STDOUT/STDERR and exception handling when shelling out in Ruby on Windows?
Nobody did. Do you? Please share in the comments.
A pair ran system updates on their Snow Leopard box which caused bunch of test failures in their project. Most of the failures were occurring around the parts of the application that used BigDecimal. After digging they found:
Oops! Looks like Apple shipped Ruby 1.8.7 p173 with a recent update. p173 has a bug that some dude introduced into BigDecimal. The fix was to update to p174 which was released quickly after this was discovered.
While on the subject, BigDecimal is kind of a drag. Its #inspect output is inhumane and new’ing up BigDecimal objects requires an ugly call to its constructor. A Pivot recommended using the undocumented bigdecimal/util which adds a convenience method to Float for creating new BigDecimals:
>> require 'bigdecimal/util'
And a nickel’s worth of free advice?
>> BigDecimal.send :alias_method, :inspect, :to_s
Unless you prefer:
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?
Kevin and I discovered that Capybara’s
Todd found out the hard way that Ruby’s
String#sprintf (also seen as the
String#%) will cast your string numbers to octal if you’re not careful. Behold:
>> "%d" % "010"
>> "%d" % "08"
ArgumentError: invalid value for Integer: "08"
from (irb):2:in `%'
Make sure you don’t feed
sprintf a string number that starts with a
0 unless 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.
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
spyOn(window, "Widget") swaps out the real
Widget function with a spy. The real
Widget implementation takes its prototype with it, which means that Widgets created while the constructor is spied on don’t get the methods a
Widget would get. That’s true even when you spy with
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,
new is 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.
Todd notifies us that in ActiveRecord, dynamic finders with too-few arguments fail silently. That is, if you say,
and fail to specify a value for
email, the value is taken to be
nil. That means that the finder will look for someone named “Todd Persen” with a
nil email 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?
It’s been a quiet week in New York City, my hometown. Let’s do the round-up.
Ask for Help
And that’s it. I’ll see you back here next week.
Live from the set of Snowpocalypse 4: The Reckoning, it’s the weekly NYC Standup Round-up!
Corey points out that the Google Maps embed code wants to be put directly on a page, not loaded on demand with something like jQuery’s
$.getScript(). Luckily, there’s a fix: adding an
async=2 param to the Google Maps API URL. More info in a post from Olly Hodgson.
Rachel and Pat found out the hard way that Bundler 0.9.8 doesn’t run on Ruby 1.8.6. Upgrade your Ruby or stick to Bundler 0.9.7.
The same team had a real headache even upgrading from Bundler 0.7.0 to 0.9.8. The gem cache directory moves and the Gemfile format changes, among other things. This sounds like more than a minor-version change to your standup scribe.
Don’t put Coca-Cola in the freezer. I know, you want it to get cold faster. You’ll come back for them in like five minutes. It seems like a great idea. But out of sight, out of mind, and the next day, you open the freezer to grab your microwave burrito and you find these waiting to explode all over you:
I’m just asking you to think this through. Do you want frozen Coke foam splattered across your nice shirt? You can put an end to this madness. Just don’t do it.
RubyMine and gem bundler don’t seem to get along – RubyMine complains that bundled gems aren’t attached but these gems aren’t available when we try to attach them. Any ideas?
RubyMine uses your gem path so you’ll be able to attach to the gem if you add your gem bundler path to your ~/.gemrc file
There’s an option to disable this nagging alert in the preferences.
Is there a good Rails plugin skeleton/template out there?
Know of one? Let us know in the comments.
Don’t use sleep 1 or such in before blocks in rspec if you need to ensure a delay between two events. A before block is ran between all nested contexts so you’re probably incurring a larger penalty. Instead, you should stub Time.now.
One team implemented git commit hooks to facilitate communication – on rebase or merge new messages from a text file in the project root are displayed to alert other pairs to changes such as gem upgrades, noteworthy database changes, etc.