Nice way to call multiple steps from a step definition

Use %-notation:

Given /^I have an article in my cart$/ do
  steps %{
    And I go the article list
    And I open the first article
    And I press "Add to cart"

Rails 3.1 gives you free down migrations

In Rails 3.1+, instead of defining a separate up and down method you can define a single method change:

class AddComparisonFieldsToReport < ActiveRecord::Migration
  def change
    add_column :reports, :compare, :boolean
    update "UPDATE reports SET compare = #{quoted_false}"
    add_column :reports, :compare_start_date, :date
    add_column :reports, :compare_end_date, :date

Migrating up works as expected:

b rake db:migrate
== AddComparisonFieldsToReport: migrating ==================================== – ad…

Updated: Test a gem in multiple versions of Rails

Updated the card with our current best practice (shared app code and specs via symlinks).

Consul 0.3.0 has a shortcut to quickly create an action map for CRUD controllers

In moderately complex authorization scenarios you will often find yourself writing a map like this:

class NotesController < ApplicationController
  power :notes, :map => {
    [:edit, :update] => :updatable_notes
    [:new, :create] => :creatable_notes
    [:destroy] => :destroyable_notes

Because this pattern is so common, Consul now has a shortcut :crud to do the same:

class NotesController < ApplicationController
  power :crud => :notes

Get the initial username which you used to login to your Linux system

If you need the initial user which you used to login to your Linux system or the time when you login you can do:

who -m

If you're in a good mood you can also do:

who am i

or (this is my favorite):

who mom likes

One purpose of this could be the .bashrc to show different Bash Promts for root to different users:

if [ `who mom likes | awk '{print $1}'` = "foobar" ]; then
   PS1='${debian_chroot:+($debian_chroot)}\[\033[41;33m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

RSpec claims nil to be false

RSpec's be_false behaves unexpectedly:

nil.should be_false
# passes, as the expectation returns true

If you want to check for false, you need to do it like this:

nil.should == false
# fails as expected


See also

RSpec: be_true does not actually check if a value is true

Install rabbitmq plugins (e.g. management plugin) on Ubuntu 12.04

If you want to install rabbitmq plugins on Ubuntu 12.04 you can do this with:


This binary is not in your default $PATH. Beause of this you have to give the full path.

Setup your terminal to not scroll when there is new output

When you are scrolling up to investigate a test failure it is super annoying when the terminal scrolls back down whenever the running test outputs another line. Luckily you can disable this behavior:

  • Gnome terminal: Edit -> Profile preferences -> Scrolling", uncheck *Scroll on output
  • Terminator: Right click on terminal screen, Preferences -> Profile -> (for each profile) -> Scrolling, uncheck Scroll on output

has_defaults is now a gem

  • has_defaults is now a gem, no longer a plugin.
  • The plugin version no longer exists. Note that plugins are no longer supported in 3.2.
  • If you are working on an application that has the plugin version of has_defaults there is no advantage to be gained from upgrading the gem. The gem is there for you should you one day upgrade to Rails 3.2+.
  • Please don't use the defaults gem which we original forked away from in 2009. It sets defaults when a field is `bl…

rake spec + rails_admin = weirdly failing specs

If you use rails_admin, your specs pass with the rspec binary, but not using rake spec (or rake parallel:spec etc), put this at the top of your spec_helper:


Don't ask.

This is probably also true for cucumber, your env.rb would be the right place.

External content

Difference between class_inheritable_attribute and class_attribute | martinciu's dev blog

How to make class_attribute behave like class_inheritable_attribte which no longer exists in Rails.

Deal with error: Expected foo_trait.rb to define FooTrait

Lately, I came across a nasty error. I had a class Article that included FooTrait and BarTrait. In BarTrait, I then accidentally called a non-existent method:

has_defaults :dummy => Dummy.non_existent_method

From that moment, no page would load anymore but always display an exception: Expected foo_trait.rb to define FooTrait. That trait had nothing to do with BarTrait.

Since it doesn't tell you what's wrong, you either remember where you were working last or you need to check all [traits](…

Run specific version of bundler

You want to run a specific, maybe older version of bundler for whatever reason?

$ bundle _1.0.21_ -v
Bundler version 1.0.21
External content

Ruby 1.8.7-p370 released

It's the last bugfix release. We will get another year of security fixes, then no more patches.

Err [...] 404 Not Found [IP: 80]

I've got often this error on just one server:

Err precise/universe amd64 Packages
404  Not Found [IP: 80]

But there was no problem with the network connection or the server.

After I deleted the local lists cache with rm -r /var/lib/apt/lists it works again.

How to deal with: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type [...] at

  1. Check if you have puppetsync enabled on the master and client

    pluginsync = true
  2. Check in /var/lib/puppet/lib there should be a […].rb somewhere. Delete it and look if it get copied again after with the next puppet run.
  3. If you are using environments make sure the puppetmaster is also in the correct environment. (d…

Rack dies when parsing large forms

  • Rack has a limit for how many form parameters it will parse.
  • This limit is 65536 by default.
  • There is a bug in Rack that will incorrectly count the number of input fields in nested forms. In my case a form with 1326 input fields was enough to break the default limit.
  • If Rack thinks your request is too large, the request will fail with a low-level Ruby message like [*Fix: "undefined method `bytesize' for #"*]( or the standard Rails error box.
  • You …
3105 cards