Skip to content

Instantly share code, notes, and snippets.

View djanowski's full-sized avatar

Damian Janowski djanowski

View GitHub Profile
Started
.
Finished in 0.000295 seconds.
1 tests, 1 assertions, 0 failures, 0 errors
# Copyright 2009 Damian Janowski. MIT License.
# http://gist.github.com/100655
#
# Very simple script to handle Gem dependencies.
# It supports a basic vendoring system
# (just gem unpack to ./vendor)
#
# List your dependencies below and require this
# file at the very top of your program (think
# of it as a replacement for your require "rubygems").
require "test/unit"
class PickTest < Test::Unit::TestCase
def test_pick
hash = {:foo => 1, :bar => 2, :baz => 3}
assert_equal({:foo => 1}, hash.pick(:foo))
assert_equal({:foo => 1, :bar => 2}, hash.pick(:foo, :bar))
assert_equal({:foo => 1}, hash.pick(:foo, :miss))
end
require 'test/unit'
class GramosTest < Test::Unit::TestCase
def test_regex
string = <<-EOS
iphone/1.0.0
iphone/beamme/1.3.0
iphone/beamme-pro/1.0.1
iphone/beamme-pitch/1.0.0
EOS
require 'rubygems'
require "sinatra"
enable :sessions
#use Rack::Session::Cookie
#use Rack::Session::Pool
get '/' do
if session[:username]
"hi, #{session[:username]}"
# Allows you to use the :session key in your tests
# (when using rack-test).
#
# get "/", {}, :session => {:user => 1}
#
class Test::Unit::TestCase
include Rack::Test::Methods
def app
Sinatra::Application
# helpers do
# def page
# @page ||= Page.new
# end
# end
class Page
attr_accessor :title
def initialize
# This assumes you have the latest Ruby 1.9 installed via MacPorts:
#
# $ sudo port sync
# $ sudo port install ruby19
#
# Make sure there are no trails of columnize, linecache, ruby-debug-base and ruby-debug.
for name in columnize linecache ruby-debug-base ruby-debug
do
(gem1.9 list | grep ^$name >/dev/null) && sudo gem1.9 uninstall -a -x -I $name
find /opt/local/lib/ruby1.9/gems/1.9.1/gems -name "$name*" -type d -maxdepth 1 -print0 | sudo xargs -0 rm -rf
# Finds all files in /opt/local/bin that are meant to be run
# with ruby1.9 (but don't have the 1.9 postfix) and renames them.
fixruby19binaries() {
for file in $(find /opt/local/bin -type f);
do
if [[ "$(head -n1 $file)" =~ "ruby1.9" ]]; then
newfile=$(echo "$file" | sed -e 's/\(1\.9\)*$/1.9/')
if [[ ! $file == $newfile ]]; then
echo "Fixing $file => $newfile"
require "rubygems"
require "thor"
class App < Thor
desc "spec", "Run RSpec"
def spec
rake do
require "spec/rake/spectask"
Spec::Rake::SpecTask.new(:default) do |t|