Peter Jaros's blog



Peter JarosPeter Jaros
NYC Standup 9/14/2011: How much is that Capybara in the window?
edit Posted by Peter Jaros on Wednesday September 14, 2011 at 01:45PM

(Or vice versa.)

Ask for Help

"How can we control popup windows when we're testing with Capybara?"

See the method within_window.

"How can I stub the current_user in a helper spec?"

Try stubbing #current_user on the helper object in the spec.

Interesting

In your AR model, if you do this

after_update :do_foo, :if => :bar_changed?
after_update :do_foo, :if => :qux_changed?

The method #do_foo will only be called after an update where qux has changed, not one where only bar has changed. The callbacks are keyed by the methods they call, so the second callback overwrites the first one entirely.

Peter JarosPeter Jaros
NY Standup 5/12/2011: It's class reloading.
edit Posted by Peter Jaros on Thursday May 12, 2011 at 09:47AM

Ask for Help

"A file is being loaded twice by Rails, and I'm not sure why. How do I figure out what's reloading it?"

Try putting this at the top of the file:

puts caller
puts "-" * 80

#caller is a Kernel method which returns the backtrace at the time it's called as an array of strings. Every time the file is loaded, you'll see the backtrace of what loaded it. The second line makes a separator so you can see the break between stacktraces.

"Is there a command that will make a new file in a path of directories that don't exist yet? Like mkdir -p but for files? Maybe touch -p?"

No. No one knows why.

Interesting Things

  • Chrome Tab Overview: Chrome can now show you an overview of all tabs in a window like Exposé does for windows. It's an experimental feature. To enable it, go to , enable "Tab Overview", and restart Chrome. Then three-finger swipe down to see all your tabs.

    Your humble reporter reminds the reader that Camino pioneered the "Tabspose" feature in 2007.

  • ERROR: current transaction is aborted: On Postgres, sometimes RSpec will show the error "ERROR: current transaction is aborted, commands ignored until end of transaction block." The backtrace of this error is not useful, because it's the backtrace of the first operation to use the database connection after some error occurred. These errors are tricky to debug.

    The people who hit it had luck with temporarily turning off use_transactional_examples in the RSpec config, which let them see the error. Just remember to turn it back on, because transactions keep your tests clean and fast. (Note: use_transactional_examples and use_transactional_fixtures are synonymous.)

Peter JarosPeter Jaros
NY Standup 5/11/2011: Chrome Frame for all my subjects!
edit Posted by Peter Jaros on Wednesday May 11, 2011 at 03:21PM

Ask for Help

"How can we expect in Jasmine that a jQuery dialog has closed?"

The dialog animates out (asynchronously, of course), and it's hard to have a test pass when it successfully disappears.

"In Javascript, How can we create an array of n empty arrays?"

One attempt, (new Array(n)).map(function() { return [] }) failed, because new Array(n) creates an array, n elements long, full of undefined. As it turns out, map() skips undefined in an array.

[Correction: new Array(n) creates an array which says its length is n, but which doesn't have any elements, not even undefined. The following does map over the undefined elements (for n=3), but isn't very useful to us.

[undefined, undefined, undefined].map(function() { return [] })

Thanks to John Pignata for pointing that out.]

Interesting Things

  • The latest version of Chrome Frame for Internet Explorer doesn't require admin rights to install.

Peter JarosPeter Jaros
NYC Standup 5/10/2011
edit Posted by Peter Jaros on Tuesday May 10, 2011 at 02:19PM

Ask for Help

"Why does RubyGems 1.8.1 say 'No method "basename" for #' when running Spork?"

It looks like RubyGems thinks that somethings a Pathname when it's actually a String. That's weird, since it seems to be entirely inside RubyGems' own code. It might have something to do with all the changes happening in RubyGems. The team's downgraded to 1.7.2 and the problem went away.

Interestingly, 1.7.2 is the version currently listed on RubyGems.org. 1.8.1, however, is what gem update --system installs.