sandro edited this page Aug 13, 2012 · 11 revisions

Workers not exiting

I've noticed that workers running Capybara don't die after sending an Interrupt signal (CTRL-C) to the dispatcher. The thin web server is registering INT and TERM signal handlers that never exit. Tell thin not to register those handlers by passing the :signals => false option:

Capybara.server do |app, port|
  require 'rack/handler/thin'
  Thin::Logging.silent = true, '', port, :signals => false).start

Why is 'mds' is eating up my processor?

Disable spotlight for the relevant directories in your System Preferences.

  • /tmp/ - Don't index rails logs
  • /usr/local - Don't index postgresql logs

Changes to the Gemfile not being observed by workers

Specjour shells out with bundle check || bundle install to keep the gems up to date. In some cases, bundle check will incorrectly return a truthy value. Due to Bundler's environment clobbering, specjour doesn't work very well when using bundle exec specjour. It's on my radar. Patches welcome. Looks like bundler > 1.2 may allow me to solve the problem:

Sharing behaviors globally (shared_examples)

Shared behaviors are typically defined globally, but specjour runs each example in its own environment, thus shared behaviors are cleared after each test run. I recommend moving your shared behaviors into a module, and including that module in each test file that depends on the shared behavior. Generally, modules are good approach anyways – as modules are the standard way to share behavior.

Here's an example:

# spec/support/nullify_empty_attributes_test.rb
module NullifyEmptyAttributesTest
  def self.included(base)
    base.class_eval do
        shared_examples 'a model with nullified empty attributes' do |*nullifyable_attributes|
          nullifyable_attributes.each do |a|
            it "nullifies an empty :#{a} attribute" do
              m = => '')
              m.send(a).should be_nil
      rescue ArgumentError => e
        # ignore the "duplicate shared behavior name error" when running in normal, *single-threaded* mode
        raise e unless e.message =~ /already exists/

# spec/models/email_address_spec.rb
describe EmailAddress do
  include NullifyEmptyAttributesTest
  it_behaves_like 'a model with nullified empty attributes', :label, :value