Skip to content

Instantly share code, notes, and snippets.

@myronmarston
myronmarston / shock.rb
Created September 14, 2012 23:13
Alternate pattern for Shock costing from Sandi Metz's GoGaRuCo Talk
class Shock
def intialize(type)
@type = type
end
def cost
coster_for(type).compute
end
private
@ndbroadbent
ndbroadbent / deploy.rake
Created September 28, 2012 22:18
Rake task for precompiling assets locally before deploying to Heroku
require 'fileutils'
# Warning: The following deploy task will completely overwrite whatever is currently deployed to Heroku.
# The deploy branch is rebased onto master, so the push needs to be forced.
desc "Deploy app to Heroku after precompiling assets"
task :deploy do
deploy_branch = 'heroku'
remote = 'heroku'
deploy_repo_dir = "tmp/heroku_deploy"
@txus
txus / inheritance_is_evil.rb
Created October 28, 2012 15:25
Solution to overuse of inheritance in your code
def Object.inherited(base)
raise "Inheritance is evil. Don't use it." unless self == Object
end
@jnicklas
jnicklas / gist:3980553
Created October 30, 2012 14:35
Capybara 2.0.0.beta4 release notes.

Hi everyone,

It's been way too long, but I finally managed to get the master branch into a state which could be considered good enough for release. I've just pushed beta4 to Rubygems. Note that this release breaks compatibility with the 1.1.x series of Capybara in major ways, it also is not compatible with previous beta versions in some ways.

Notably, we changed the :type that Capybara assumes your specs run under in RSpec to :feature (previously it was :request). The latest release of spec/features. Alternatively you can use the Capybara Feature DSL (feature instead of describe), which should work without any additional tweaking. If you see errors like undefined method visit, then you're probably encountering this issue. If you're including modules into :request specs, you will probably need to change that to :feature.

This release also drops official support for Ruby 1.8.x. It's time to migrate, folks!

Many thanks to the many contributors for all the help with this release. Without you

Capybara.add_selector :record do
xpath { |record| XPath.css("#" + ActionController::RecordIdentifier.dom_id(record)) }
match { |record| record.is_a?(ActiveRecord::Base) }
end
Dir.glob(File.join(File.dirname(__FILE__), "../../../app/**/*_decorator*.rb")) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
@mattwynne
mattwynne / integrated_docs.rb
Created November 21, 2012 00:27
Integrated documentation for Ruby
# For context, this was inspired by the RubyRogues podcast #79 where they talked about
# documentation in Ruby, and specifically grumbled quite a bit about the failings of RDoc.
#
# http://rubyrogues.com/079-rr-documenting-code/
#
# As someone who's spent a lot of time using an IDE for programming C# and Java, I think
# Ruby could do a lot better at putting documentation at our fingertips as we program.
#
# Maybe making the documentation part of the structure of the code would facilitate this?
#
require "timeout"
module WaitSteps
extend RSpec::Matchers::DSL
matcher :become_true do
match do |block|
begin
Timeout.timeout(Capybara.default_wait_time) do
sleep(0.1) until value = block.call
@solnic
solnic / rvm_remove_old.sh
Created December 4, 2012 09:34
Remove all rubies older than given date
DATE=2012-06-01
for version in `find $rvm_path/rubies/ -mindepth 1 -maxdepth 1 -type d -not -newermt $DATE | cut -d / -f 7`; do rvm remove $version; done
@myronmarston
myronmarston / my_class_spec.rb
Last active December 11, 2015 14:58
Demonstration of how to override the default implicit subject in rspec.
class MyClass
def initialize
raise "Initialize was called"
end
end
# Declare a shared_context that is included in all example groups
# (using `:example_group => { :file_path => // }` to match all
# example groups.
shared_context "using allocate instead of initalize", :example_group => { :file_path => // } do