You dont need RSpec in :development

You can speed up development load time and get rid of rspec in development if you simply not require it in :development and just load the tasks in the Rakefile where they are needed.

# Gemfile
group :development, :test do
  gem 'rspec-rails', :require => false
end

# Rakefile
require File.expand_path('../config/application', __FILE__)
require 'rspec-rails' if ['test', 'development'].include?(Rails.env)
...

Repeat for any other testing lib for even more speedup 🙂

Running tests via spork directly from Rubymine

Very fast test execution from inside Rubymine.
Cmd+F8 + 2 seconds == test results 😀

1 Activate DRB in Rubymine
Run > Edit configurations > Defaults > RSpec > Use DRB Server

2 a) Start spork from Rubymine
Tools > Run Spork DRB Server

2 b) (alternatively) start spork from the commandline
Code

  # spec/spec_helper.rb
Spork.prefork do
  if ENV["RUBYMINE_HOME"]
    puts "Rubymine support"
    $:.unshift(File.expand_path("rb/testing/patch/common", ENV["RUBYMINE_HOME"]))
    $:.unshift(File.expand_path("rb/testing/patch/bdd", ENV["RUBYMINE_HOME"]))
  end
end

and run it via:

RUBYMINE_HOME=/Applications/Rubymine\ 3.2.4.app/ spork

Adding travis hook to new github project via the commandline

I got tired of clicking through the github menus, so after some toying around with the octopi github client (which does not work as expected…), I wrote this small script using pure rest-client.

Creates a new travis hook based on the travis info in your .gitconfig
and also triggers the initial test-run.

add to ~/.gitconfig

[travis]
  user = xxx
  token = yyy

download & run the Script
wget https://raw.github.com/grosser/dotfiles/master/bin/github-add-travis

./github-add-travis github-password project-name

Switching form Public Domain to MIT

All my new projects will be released under MIT / those I work on will be switched, which will still means the same as before: Do wtf you want with this code, no need for any naming/license copying.

After reading some articles I realized that public domain does not always work since some countries do not allow it and its also unclear what happens when the code causes problems <-> lawsuit.

Ill also try to add a s.license = ‘MIT’ to all gemspecs, to make license management easier.

Ruby Money vs nil — aka undefined method `round’ for nil:NilClass

Problem
When using composed_of with Money you get this nice error when trying to get the money object while the cents column is nil.
Additionally Money.new(nil) does not work, neither do strings like Money.new(params[:cents]).

Solution
Overwrite the initializer to also accept nil and strings

# config/initializers/money.rb
require 'money'
class Money
  def initialize_with_default_currency(*args)
    args[0] = args[0].to_i if args[0].is_a?(String) or args[0].blank?
    args[1] ||= Money.default_currency
    initialize_without_default_currency(*args)
  end
  alias_method_chain :initialize, :default_currency
end