Skip to content

Instantly share code, notes, and snippets.

View bcardarella's full-sized avatar
Out sailing

Brian Cardarella bcardarella

Out sailing
View GitHub Profile
@bcardarella
bcardarella / .autotest
Created April 20, 2009 18:53 — forked from technicalpickles/.autotest
Evil Autotest has Temper Tantrums
# http://gist.github.com/10524
# Prevents autotest from running your entire test suite after fixing a failed test.
# Works with ZenTest 3.10.0
# Place this in your .autotest file:
require 'rubygems'
require 'active_support'
class Autotest
def run_with_not_rerunning_everything
hook :initialize
@bcardarella
bcardarella / gist:98869
Created April 21, 2009 01:06
Benchmark your Test::Unit tests
require 'test/unit'
require 'benchmark'
class Test::Unit::TestCase
alias_method :real_run, :run unless instance_methods.include?("real_run")
@@total = {}
def run(result)
if block_given?
test = ::Benchmark.measure { real_run(result) { yield } }
require 'rubygems'
require 'wirble'
require 'pp'
Wirble.init
Wirble.colorize
class Object
def local_methods
(methods - Object.instance_methods).sort
Dan Pickett, http://en.oreilly.com/rails2009/profile/46469
Brian Cardarella, http://en.oreilly.com/rails2009/profile/45790
context "My Custom Query" do
setup do
@positive_record = positive_record_getter
@negative_record = negative_record_getter
@result_set = Report.custom_query
end
should "have a result set that contains the positive record" do
assert_contains @result_set, @positive_record
end
---
:UY: Uruguay
:NP: Nepal
:BS: Bahamas
:HT: Haiti
:LK: Sri Lanka
:SE: Sweden
:DZ: Algeria
:TW: Taiwan
:GU: Guam
:HI: Hawaii
:KY: Kentucky
:MN: Minnesota
:OK: Oklahoma
:FM: Federated States Of Micronesia
:MT: Montana
:NJ: New Jersey
:PW: Palau
:SD: South Dakota
:VI: Virgin Islands
@bcardarella
bcardarella / round_to_precision.rb
Created September 11, 2009 23:04
Float#round_to_faction
class Float
# Takes a fraction and will round a float to the nearest multiple
# >> k = 0.4
# >> k.round_to_fraction
# => 0.5
# >> k = 0.75
# >> k.round_to_fraction
# => 1.0
# >> k.round_to_fraction(0.65)
@bcardarella
bcardarella / have_named_scope.rb
Created September 22, 2009 16:22
Should Have Named Scope matcher for Rspec
module Shoulda # :nodoc:
module ActiveRecord # :nodoc:
# Examples:
# class Book < ActiveRecord::Base
# named_scope :test, :conditions => { :name => "test" }
# named_scope :by_name, lambda { |n| { :conditions => { :name => n} } }
# end
#
# RSpec:
# HaveFilter matchers for RSpec
# save as: spec/support/have_filter.rb
#
# class HomeController < ApplicationController
# before_filter :require_user, :except => [:action_1, :action_2]
# ...
# end
#
# describe HomeController do
# it { should have_before_filter(:require_user).except(:action_1, :action_2) }