Skip to content

Instantly share code, notes, and snippets.

class Customer
def initialize(attrs = {})
@id = attrs[:id]
@country = attrs[:country]
end
def tax_code
TaxCodes[@country].call(@id)
rescue
raise "Tax codes for #{@country} not supported"
@croaky
croaky / thank-you.md
Created November 9, 2012 22:44 — forked from anonymous/thank-you.md
This Week in Open Source

This Week in Open Source

Thanks to this week's contributors to thoughtbot projects.

Test your Ruby gem against different versions of its dependencies.

avatar Joe Ferris

@croaky
croaky / gist:2401393
Created April 16, 2012 20:43 — forked from kevinzen/gist:2400225
Advice on DRYing this test up?
FIREFOX_FIXTURES = [
{
browser: 'Firefox',
gecko_version: '20101203',
os: 'Intel Mac OS X 10.6',
platform: 'Macintosh',
raw: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
version: '3.6.13'
},
{
@croaky
croaky / HOW_TO.md
Created March 16, 2012 05:43 — forked from michaeldauria/gist:2048022
Migrate from Copycopter 1.0 (hosted by thoughtbot) to Copycopter 2.0 (open source, deploy your own instance)

Use the latest version of the copycopter_client gem:

gem 'copycopter_client', '2.0.0'

Export your published drafts from copycopter.com:

RAILS_ENV=production bundle exec rake copycopter:export

This will create a config/locales/copycopter.yml file.

@croaky
croaky / gist:1385953
Created November 22, 2011 15:36 — forked from mperham/gist:1379464
Flexibility without Dependency Injection
class TaxCode
GENERATORS = {
:us => lambda { |id| "US-#{id}" },
:br => lambda { |id| "#{id + 9}-BRA" },
}
def self.generate(code, id)
gen = GENERATORS[code] || raise ArgumentError, "No generator for country #{code}"
gen.call(id)
end
@croaky
croaky / new.rb
Created November 9, 2010 18:56 — forked from jferris/new.rb
describe Message do
FactoryGirl.create :account, :name => "My Account" do
create :user
create :project do
build :message, :author => :user
end
end
# examples
end
@croaky
croaky / new.rb
Created November 9, 2010 18:46 — forked from jferris/new.rb
FactoryGirl.define do
sequence :email do |n|
"user#{n}@example.com"
end
factory :user, :aliases => [:author] do
email
password "test"
end

The problem is that it's hard to achieve the same result as Shoulda/Remarkable matchers using only RSpec:

it {
  user = User.new
  user.should be_invalid
  user.errors[:email].should include("can't be blank")
}

It would be nice however, if we provide something like this:

@croaky
croaky / .gems
Created September 9, 2009 00:08 — forked from bmizerany/.gems
rack_hoptoad