Skip to content

Instantly share code, notes, and snippets.

View mattscilipoti's full-sized avatar

Matt Scilipoti mattscilipoti

View GitHub Profile
@mattscilipoti
mattscilipoti / README
Created June 24, 2009 14:45
cucumber setup
Run all features:
`cucumber`
Run cucumber using selenium:
`cucumber -p selenium features`
TODO: we may be able to clean up the file locations using --exclude in the profiles
#usage: Incident.new.should delegate(:batch_code, :to => :incident_batch)
Spec::Matchers.define :delegate do |method_name, options|
match do |delegator|
associated_receiver = options[:to]
expected_value = 'TEST'
receiver = Spec::Mocks::Mock.new(associated_receiver, method_name => expected_value)
##retrieval
delegator.stub!(associated_receiver => receiver)
delegator.send(method_name) == expected_value
@mattscilipoti
mattscilipoti / crontab
Created August 18, 2009 14:09
script/runner and crontab
MAILTO=me@example.com
TIPS_ROOT=/home/user_name/projects/project1
# m h dom mon dow command
*/1 * * * * $TIPS_ROOT/script/local_runner.sh script/ping_em_all.rb log/ping.log
require 'rubygems'
require 'wirble'
#require 'utility_belt' #didn't play well with others, try again later.
require 'hirb' #nice console formatting
Wirble.init
Wirble.colorize
Hirb.enable
puts "`include RailsHelper` for named_urls, helpers, etc."
Transform /^table:.*$/ do |table|
#convert empty strings to nil (reverses #470)
table.hashes.each do |hash|
hash.each do |key, value|
hash[key] = value.empty? ? nil : value
end
end
table
end
@mattscilipoti
mattscilipoti / irb_rails_helper.rb
Created October 27, 2009 14:40
.irbrc RailsHelper
puts "`include RailsHelper` for named_urls, helpers, etc."
module RailsHelper
def self.included(base)
##from: http://kpumuk.info/ruby-on-rails/memo-6-using-named-routes-and-url_for-outside-the-controller-in-ruby-on-rails/
## this is slow because all routes and resources being calculated now
base.send('include', ActionController::UrlWriter)
base.default_url_options[:host] = 'www.example.com'
DatabaseCleaner.strategy = :truncation, {:except => SeedData.seed_tables}
puts "You can now utilize named_urls & DatabaseCleaner.clean"
#When I edit Jurisdiction/Location:L1
When /^I edit (.*)(?:\/)(.+):(.+)$/ do |requested_parent_model, requested_model, default_identifier|
@mattscilipoti
mattscilipoti / rspec_recent.rake
Created November 4, 2009 18:49
rake -g spec:recent
#save to ~/.rake/rspec_recent.rake
@usage: `rake -g spec:recent`
# Grab recently touched specs
#from: http://nullcreations.net/entries/general/rspec-on-rails-rake-task-for-recent-specs
#TODO: should this grab list from svn? affter we remove externals?
def recent_specs(touched_since)
recent_specs = FileList['app/**/*'].map do |path|
if File.mtime(path) > touched_since
We couldn’t find that file to show.
@mattscilipoti
mattscilipoti / log.rb
Created January 28, 2010 17:00 — forked from canadaduane/log.rb
log in json format
require 'json'
$log_filename ||= File.expand_path(File.join("..", "ruby.log.json"), File.dirname(__FILE__))
begin
if !File.exist?($log_filename)
File.open($log_filename, "w") do |f|
f.write "["
end
end