This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post | |
def initialize(attributes = {}) | |
@attributes = attributes | |
end | |
def publishable? | |
@attributes[:approved] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IRBRC file by Iain Hecker, http://iain.nl | |
# put all this in your ~/.irbrc | |
require 'rubygems' | |
require 'yaml' | |
alias q exit | |
class Object | |
def local_methods | |
(methods - Object.instance_methods).sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright 2010, Iain Hecker. All Rights Reserved | |
# Conway's Game of Life, in one line of Ruby. | |
# http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life | |
# Tested and found working on Ruby 1.8.7 and 1.9.2 | |
# The grid is spherical or "wrap around", so the left is connected to the right and top to bottom. | |
# | |
# Generate a random grid, 30 cells wide and 10 cells high | |
# | |
# grid = "30x10".to_grid | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hoptoad webistrano recipe | |
# works with Rails 3 | |
after "deploy", "deploy:notify_hoptoad" | |
after "deploy:migrations", "deploy:notify_hoptoad" | |
namespace :deploy do | |
desc "Notify Hoptoad of the deployment" | |
task :notify_hoptoad do | |
rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rake.application.instance_variable_get('@tasks')['default'].prerequisites.delete('test') | |
task :default => :spec | |
task :stats => "spec:statsetup" | |
desc "Run all specs in spec directory (excluding plugin specs)" | |
task :spec => :"spec:load" do | |
RSpec.run(:all) # or something similar | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RSpec | |
module Expectations | |
# If Test::Unit is loaed, we'll use its error as baseclass, so that Test::Unit | |
# will report unmet RSpec expectations as failures rather than errors. | |
superclass = ['Test::Unit::AssertionFailedError', '::StandardError'].map do |c| | |
eval(c) rescue nil | |
end.compact.first | |
class ExpectationNotMetError < superclass | |
def spec_failure? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveRecord::StatementInvalid (Mysql2::Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like': SELECT `tags`.* FROM `tags` WHERE (name LIKE '☃')): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ValidationMatcher | |
class Validate | |
include RSpec::Matchers::Pretty | |
attr_accessor :attribute, :values, :target, :results, :value_description | |
def initialize(attribute) | |
self.attribute = attribute | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ruby-1.9.2@fuubar fuubar develop / $ rspec spec | |
FFFFFFFFFFFFFFFFFFF | |
Failures: | |
1) Fuubar start should create a new ProgressBar | |
Failure/Error: @output = StringIO.new | |
uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Nested_1::StringIO | |
# ./spec/fuubar_spec.rb:6:in `block (2 levels) in <top (required)>' | |
2) Fuubar start should set the title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
God.watch do |w| | |
DEFAULT.call(w) | |
w.name = "delayed_job" | |
w.start = "bundle exec #{RAILS_ROOT}/script/delayed_job -e #{RAILS_ENV} run" | |
w.pid_file = "#{RAILS_ROOT}/tmp/pids/delayed_job.pid" | |
end |