Autonomous Machine

Posts from 2011

Teaching Ruby/ProgressBar to play nice with log files

From my pull request:

We have several scripts we use during application development that monitor long running processes with ruby-progressbar. We also have these scripts running in automated environments (such as CI), and the output in these situations is very noisy. We could alter the scripts, but I think it would be nicer if this library could gracefully handle these situations.

This patch adds a baseline behavior in non-tty environments so that things like log files aren't filled with every frame of the progress bar animation.

This was merged into the master branch, so one can pick up the change by using a git source in her Gemfile.

  • December 17, 2011
  • Article
  • Ruby

A Brief Summary of 2 Mongoid Search Libraries

In the course of developing Forkchop, I've tried out a few of the Mongoid-compatible search plugins.

The goal of these libraries is to provide lightweight search functionality that precludes the need for a full search engine. And while most projects will graduate to something like Sphinx (or IndexTank or Lucene/Solr), it's nice to be able to start out with something simpler when a project's search needs are still basic.

Mongoid Search

This library is a better choice for searching the text of articles. It doesn't offer nearly as many options as Mongoid Fulltext Search, but its code is much shorter and extensible. I am currently using this library and paginating result sets with Kaminari.

Mongoid Fulltext Search

This project is best suited for providing autocomplete-type functionality. I tried to use it first, but ran into some problems trying to modify it's behavior (for example, there isn't an easy way to use an $any query instead of $all without overriding a large internal method).

  • October 17, 2011
  • Article
  • mongoid, rails, search

Cucumber, Capybara, Selenium, and Alerts

Although I try to avoid alert boxes in general, sometimes using them makes sense, especially when initially building out a feature.

This morning I was using Cucumber (and Capybara) to test deleting an object on a small project, and I needed to figure out how to click OK to dismiss in an alert and have the scenario continue. Here's the Cucumber step I ended up using:

When /^I click OK in the alert box$/ do
  page.driver.browser.switch_to.alert.accept
end

alert is returning an instance of Selenium::WebDriver::Alert, which also responds to dismiss and send_keys should you need to do something other than just click OK.

  • August 25, 2011
  • Article
  • Capybara, Cucumber, Ruby, Selenium