Ylan Segal

StandardError Casts Message to String in Ruby 1.9

When passing a message to StandardError in ruby 1.8, it will keep that object intact. Ruby 1.9 will convert to a String. Spent more time than I wanted to chasing this down.

In ruby 1.8.7:

1
2
3
4
5
6
>> RUBY_VERSION
=> "1.8.7"
>> err = StandardError.new(Object.new)
=> #<StandardError: #<StandardError:0x78952527>>
>> err.message.class
=> Object

In ruby 1.9.3:

1
2
3
4
5
6
>> RUBY_VERSION
=> "1.9.3"
>> err = StandardError.new(Object.new)
=> #<StandardError: #<Object:0x456c5f50>>
>> err.message.class
=> String

Run Changed Specs

I usually create a branch while working on a feature or bug. I found it helpful to add the following script to my path:

1
2
3
#! /bin/bash

git diff --name-only master..HEAD | grep 'spec.rb' | xargs rspec

It’s quick and dirty, but effective. It asks git for a list of filenames that have changed in the current branch, filters them to find specs and runs them with rspec.

Faster Rspec: Jruby, Spork and Nailgun

UPDATE: You can use bundler binstubs to squeeze a bit more performance


Much has been said about Rails slow start-up time on large projects. It is especially painful when trying to do TDD and each test takes 30 seconds to run, mainly in startup time.

As a consequence, there have been many attempts to pre-load the Rails environment and have it ready to test. I tested some options and saved 25 seconds on each test run.

Per-Project Environment Variables

I wrote before about using foreman to manage you app’s processes. An additional feature is that it enables you to configure your unix environment when starting an app, by reading environment variables located in a .env file at the root of your project, that looks something like this:

.env
1
2
MY_VARIABLE=/some/path
SECRET_STUFF=get_a_better_password

It is certainly a great feature for setting an common environment for processes that your start with foreman. However, processes that are started manually, like for example a rails console, don’t have this environment setup. Of course, you can always set them manually in your shell profile, but now they need to be maintained in two different places.