Duplo

Building Blocks & Learning Experiences

Browsing Posts in Ruby

I ran across a really obscure and subtle bug in Ruby 1.9, which was triggered by RSpec including a module for the purpose of altering RSpec::Mock objects before they’re serialized to YAML. I was attempting to update a work project from REE 1.8.7 to MRI 1.9.3. Some of the tests were failing with a SystemStackOverflow: [...]

I was having some trouble running rspec within Emacs. One of the gems in my Gemfile was pointing to a git repo, and as a result, bundle was shelling out through Emacs to check my revision using this method: def revision_from_git if File.exists?(scope(‘.git/HEAD’)) Dir.chdir scope(“.”) do `git rev-parse HEAD` end end end Since my git [...]

If you happen to have a <select> tag with its multiple attribute set, you can unselect them in Cucumber by adding this step: When /^(?:|I )unselect “([^"]*)” from “([^"]*)”$/ do |value, field|   unselect(value, :from => field) end

The uservoice gem provides a nice easy way to integrate your Rails app with the UserVoice user feedback service. If you’re using Heroku to deploy your Rails app, there are two things that will provide speed bumps. The first is that, short of storing your UserVoice API key in your git repository, there’s no way [...]

This post is a reminder to myself, that when I upgrade my webrat gem, I need to replace its vendor/selenium-server.jar. If I forget, then Selenium Remote Control will most likely break because the version of selenium-server.jar included with webrat is old, and doesn’t support current versions of Firefox.

I’ve often been sad that there is no default keybinding for comment-region in Emacs’s ruby-mode. Eventually it annoyed me enough that I added one: (add-hook ‘ruby-mode-hook (lambda () (define-key ruby-mode-map “\C-c#” ‘comment-or-uncomment-region) ) ) This assigns C-c # to comment the current region, or if the current region is already commented, it will uncomment the [...]

Autotest-inotify is a gem that extends autotest to use Linux’s inotify to monitor changes to your source and test files, running the appropriate tests as files are modified. By default, autotest implements filesystem polling to detect these changes. This can use a significant amount of CPU cycles1, and can impact battery life in laptops. Through [...]

In the process of setting up metric_fu, I found that, one way or another, saikuro’s output wasn’t getting into the correct place. I’ll spare you the long story, and just show the config settings I had to put into my Rakefile to get things working: config.saikuro = { :output_directory => “#{ENV["CC_BUILD_ARTIFACTS"]}/scratch/saikuro”, :input_directory => ["app\" --input_directory [...]

There are a number of different ways to handle custom error pages in rails. Most use rails’s rescue_from method. This approach allows your error pages to be dynamically rendered in response to errors. The way I see it, if my site has just encountered an error, I want to immediately go into damage control mode. [...]

Voyeur is a very small bit of ruby code that I’ve written to display updates to your MPD stream via Growl. You can find it here:  http://kill-0.com/voyeur/ You start and stop it as you would a daemon, ie $ ./voyeur start and ./voyeur stop. As an added bonus, you can send it a HUP signal, [...]