Jacob Maine's blog



Jacob MaineJacob Maine
Standup 2012/2/1: Speed kills
edit Posted by Jacob Maine on Wednesday February 01, 2012 at 10:17AM

Interesting Things

  • If you haven't noticed, Jasmine tests are at least twice as fast in Chrome as they are in Firefox. Closing the inspection pane makes it even faster. Be aware that part of the speed is from Chrome's aggressive caching, which can lead to erroneous test results.
  • One team is using Backbone's local storage. When they add model.clear() after every test run, their tests go from 20 seconds to over 100 seconds. Someone suggested the silent: true option, to suppress the change events that clear triggers.
  • To avoid bugs in minified JS put semicolons in the right spots. The easiest way to do that is to run a tool like JSLint or JSHint over your code. Add it to your test suite to prevent mistakes.

Ask for Help

  • "In IE8 the numbers don't show up on ordered lists if we dynamically create lis"

Or rather, they do, but only after hovering over the list. The common wisdom is that this has been broken in IE for a long time.

  • "Our project does some DNS resolution. Is there a preferred way to mock this in tests?"

No suggestions.

  • "When replying to an email each email system adds different junk to the message. We're processing those incoming replies. Any standard way to strip out the junk?"

Everyone is using the ugly regex approach. Are there mail gems that handle this?

Jacob MaineJacob Maine
Standup 2012/1/31: The bleeding edge
edit Posted by Jacob Maine on Tuesday January 31, 2012 at 10:09AM

Interesting Things

  • There's a new release of Backbone - 0.9.0. It's billed as a release candidate for 1.0, and seems to be a bit buggy, as RCs can be. However, it's exciting to see that Backbone is getting close to that milestone.
  • You should default boolean fields to true or false, at the database layer. Otherwise your queries have to deal with three-valued logic.
  • Rails 3.2 has some unexpected behavior. First, the generated form ids have changed ... what used to be id=user_new is now id=new_user. Second, if your routes file is missing an entry, you will no longer get errors in controller tests. If you liked that behavior, try out request specs.

Ask for Help

  • "Anyone seen problems with the latest REE and iconv?"

Everything works on the Linux machines, but on Macs, there's an error about an unrecognized target encoding. Iconv works on the command line, so it's something about REE.

Jacob MaineJacob Maine
Standup 1/30/2012: It's all about sharing
edit Posted by Jacob Maine on Monday January 30, 2012 at 10:07AM

Interesting Things

  • should_not render_with_layout can be flaky. For example, asserting that an XHR request doesn't have a layout could fail if the request renders an email template that does have a layout. These matchers are not very sophisticated, mostly doing string matching, not real template resolution.

Ask for Help

Since the models are all built beforehand, it's tricky to write tests that make assertions about relative time. There were a variety of suggestions. You can write all the tests relative to a model: some_time.should == model.created_at - 3.days. You can wrap the entire suite and fixture generation in a Timecop block, but you'll have to deal with losing that context whenever any test calls Timecop.return.

  • "How do I separate multiple FixtureBuilder files, but allow them to reference objects created in each other?"

Typically you want to separate fixtures into smaller files. But, you also often want to reference objects in other files, for example so you can assign a user from user_fixtures.rb to a post in post_fixtures.rb. One solution is to eval each file in a loop, so they can share instance variables. You can also use User.where(:name => "Tom") but that's awkward and repetitive.

  • "Any suggestions for a CMS that would allow lots of different visual presentations of the content?"

The questioner is experimenting with branding. Not many suggestions... a shared database perhaps?

Jacob MaineJacob Maine
SF Standup 3/4-3/5/2010
edit Posted by Jacob Maine on Friday March 05, 2010 at 09:25AM

Help

"What's the best way to test that an array contains another array?"

A custom matcher using array - other_array was suggested.

Interesting

The team that was having problems with Prototype response codes found a partial solution.

They sometimes call abort() on the request which triggers the callbacks with a 0 response code. They found that if they set transport.onreadystatechange = function() {}; before calling abort() they could skip the callbacks, and manually call whatever clean-up they needed. That Prototype interprets 0 as a success still sounds strange.

Jacob MaineJacob Maine
SF Standup 3/2/2010: Rubyconf Proposal workshop
edit Posted by Jacob Maine on Tuesday March 02, 2010 at 09:19AM
  • Reminder: tonight we're hosting a workshop to help you polish your RailsConf presentation proposal. Sign up or just drop in. Thanks to our own Sarah Mei for coordinating and running the workshop.
  • "Anyone familiar with the new RubyMine test runner? We'd like to integrate Jasmine tests, so we can run headless JS tests in the IDE."

Jacob MaineJacob Maine
Standup 7/27/2009: Testing Partial Locals
edit Posted by Jacob Maine on Monday July 27, 2009 at 09:05AM

Ask for Help

"What's the best way to test that a controller (a) renders a partial and (b) passes the partial the right locals?"

Mocking render_template and the locals ends up mocking too much of the request cycle. Ideally, we'd like something like:

response.should render_partial("item", :locals => {:item => assigns[:item]})

"Hpricot breaks with xml elements named param. Any suggestions?"

Works if we replace Hpricot with Nokogiri, so that may be the way to go.

Interesting Things

  • A follow up on the problems using Fixture Scenarios with Rails 2.3.2: The fixture are loading twice, although it's not clear why. The second run barfs with a syntax error. Perhaps the first run doesn't properly close the fixture file?
  • Raising the timeout fixed issues with S3 uploads over slow connections. It might also be more efficient. The timeout could stop a 90% complete upload, then kick off a retry (the gem has a 3 retry policy), which further clogs the tubes.