Skip to content

Instantly share code, notes, and snippets.

View kevinrutherford's full-sized avatar

Kevin Rutherford kevinrutherford

View GitHub Profile
require 'machine'
require 'robot'
describe Robot do
before :each do
@robot = Robot.new
end
describe 'when new' do
it 'should have no location yet' do
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0])) # should count as 2
return nil, block, nil
end
opt = (val = parse_arg(val, &error))[1] # counts as 1; should count as 2
val = conv_arg(*val)
if opt and !arg # counts as 1; should count as 2 (or 3?)
argv.shift
else
val[0] = nil
@kevinrutherford
kevinrutherford / book_spec.rb
Created May 23, 2011 15:55
Book should be visitable
require 'spec_helper'
describe Book do
it_should_behave_like 'a visitable item'
# more specs ...
end
@kevinrutherford
kevinrutherford / visitable_contract.rb
Created May 23, 2011 15:57
Contract test for visiables
shared_examples_for 'a visitable item' do
its(:name) { should_not be_nil }
end
@kevinrutherford
kevinrutherford / spec_helper.rb
Created August 7, 2011 10:59
Mocking warden in controller specs
module RandomHelpers
def random_number() SecureRandom.random_number(10000); end
def random_id() random_number; end
def random_name() SecureRandom.hex(20); end
end
module ControllerHelpers
def user_double(attrs = {})
user_attrs = {
:first_name => random_name,
class MyController < ApplicationController
def show
@sysinfo = SysInfo.new(model_stuff, ...)
end
end
@kevinrutherford
kevinrutherford / rvm_history.sh
Created June 18, 2012 17:41
Bash shell history showing RVM issue on Ubuntu 12.04
$ cd ~
$ rm -rf .rvm
$ curl -L https://get.rvm.io | bash -s stable
# ...
$ type rvm | head -n 1
rvm is a function
$ rvm install 1.8.7
# ...
$ rvm use 1.8.7
# ...
@kevinrutherford
kevinrutherford / rvm_history.sh
Created June 18, 2012 19:06
Transcript of a clean RVM installation on Ubuntu 12.04
$ uname -a
Linux kr-laptop 3.2.0-25-generic #40-Ubuntu SMP Wed May 23 20:30:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
$ rvm implode
# and edit .bashrc to remove RVM stuff there
# No RVM packages installed, no RVM gem, no other RVM config files found
$ curl -L https://get.rvm.io | bash -s stable
#...
rvm 1.14.2 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ . /home/kevin/.rvm/scripts/rvm
$ ls -l /home/kevin/.rvm/gems/ruby-1.9.3-p194@global/bin
total 16
-rwxr-xr-x 1 kevin kevin 395 Jun 18 20:49 bundle
-rwxr-xr-x 1 kevin kevin 384 Jun 18 20:49 rake
-rwxr-xr-x 1 kevin kevin 444 Jun 18 20:49 rubygems-bundler-uninstaller
-rwxrwxr-x 1 kevin kevin 296 Jun 18 19:56 ruby_noexec_wrapper
@kevinrutherford
kevinrutherford / publishes_posts.rb
Created July 6, 2012 14:48
A classic finder returning nil
Post = Class.new # Just a placeholder to make the tests run
class PublishesPosts < Struct.new(:post_id, :ui)
def run
post = Post.find_by_id(post_id)
if post
post.publish
ui.post_published(post)
else