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
#!/usr/bin/env ruby -wKU | |
# Don't allow user to commit code containing the symbol "NOCOMMIT". | |
if system "git diff --cached | grep -q '^\+.*NOCOMMIT'" | |
puts "Can't commit: NOCOMMITs found in code." | |
system "git grep --cached -n NOCOMMIT" | |
exit 1 | |
else | |
exit 0 |
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 BeValid | |
def matches?(target) | |
@target = target | |
@target.valid? | |
end | |
def failure_message | |
"expected #{@target} to be valid, but:\n" + | |
@target.errors.map { |a, m| "- #{a.humanize} #{m} (#{a}: #{@target[a].inspect})" }.join("\n") | |
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 HaveAMatcher | |
class HaveA | |
def method_missing(attribute) | |
@attribute ||= attribute | |
self | |
end | |
def matches?(target) | |
@target = target | |
raise ArgumentError, "No attribute specified for have(:a)" unless @attribute | |
@value = @target.__send__(@attribute) |
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
# Lets you just say 'render' in a view spec. The path is | |
# discovered from the describe block. | |
# This is here so you can config.include(RenderHelper) to use this feature. | |
module RenderHelper | |
def self.included(mod) | |
if mod.ancestors.include? Spec::Rails::Example::RailsExampleGroup | |
Spec::Rails::Example::ViewExampleGroup.instance_eval do | |
def inherited(subclass) | |
super |
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
# config.include(HaveTagExtensions) to do things like: | |
# | |
# response.should have_tag("form input#email") do | |
# with_value("[email protected]") | |
# end | |
# | |
# response.should have_tag("strong") do | |
# with_text("Important!") | |
# end | |
module HaveTagExtensions |
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
# Not (yet) functional. | |
module AssignMatcher | |
class Assign | |
def initialize(assignment) | |
@assignment = assignment | |
end | |
def matches?(target) | |
@target = target | |
@value = assigns[@assignment] | |
[email protected]? |
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
# klass.first_responder(:method) gives you the Module in klass's inheritance chain which will respond to :method. | |
# klass.all_responders(:method) gives you all of the Modules in klass's inheritance chain which can respond to :method, in order from klass to Kernel. | |
require 'metaid' | |
class Object | |
def first_responder(method) | |
method = method.to_s | |
metaclass.ancestors.find do |mod| | |
mod.instance_methods(false).include? method |
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
# Git aliases for bash | |
alias gst='git status' | |
alias gf='git fetch' | |
alias gl='git pull' | |
alias gp='git push' | |
alias gc='git commit -v' | |
alias gca='git commit -v -a' | |
alias gb='git branch' | |
alias gba='git branch -a' |
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
# CerealPagination: Demeter's Revenge for will_paginate. | |
# | |
# For every has_many :foos association, creates a paginate_foos | |
# method which calls foos.paginate. | |
# | |
# TODO: Support has_and_belongs_to_many. | |
module CerealPagination | |
def self.included(base) | |
base.instance_eval do |
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
# If you've got pending migrations, tells you why all your tests/specs failed. | |
module Autotest::Migrations | |
Autotest.add_hook :ran_command do |autotest| | |
if autotest.class.name =~ /Rails/ | |
system "rake db:abort_if_pending_migrations" | |
end | |
end | |
end |
OlderNewer