Skip to content

Instantly share code, notes, and snippets.

.DS_Store
*.csv
*.pdf
# For mocha integration, add this file into features/support folder
require "mocha"
World(Mocha::Standalone)
Before do
mocha_setup
end
#!/bin/bash
echo "Setting up chef..."
sudo apt-get -y update
sudo apt-get -y install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget ssl-cert
cd /tmp
wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
tar zxf rubygems-1.3.4.tgz
This example shows how to setup an environment running Rails 3 beta 3 under 1.9.2-head with a 'rails3' gem set.
∴ rvm update --head
# ((Open a new shell)) or do 'rvm reload'
# If you do not already have the ruby interpreter installed, install it:
∴ rvm install 1.9.2-head
# Switch to 1.9.2-head and gemset rails3, create if it doesn't exist.
∴ rvm --create use 1.9.2-head@rails3
-- Used Ubuntu 10.04 Lucid Canonical, ubuntu@ ami-2d4aa444
sudo apt-get install ruby-full build-essential
ruby --version
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
sudo apt-get install rubygems
sudo gem install rubygems-update
sudo /var/lib/gems/1.8/bin/update_rubygems
sudo emacs ~/.bashrc
-- add the line below and save
export PATH=/var/lib/gems/1.8/bin:$PATH
@mattsnyder
mattsnyder / contain_within_matcher.rb
Created April 15, 2011 18:02
Contain Within Matcher for use in your view specs. Faster than css_select and assert_select.
# Must have Nokogiri gem installed and save this file in your spec/support dir
# Allows you to write cleaner/faster specs in your views (50% faster than css_select)
# Increased readability in your spec doc
# ex.
# rendered.should contain('my heading').within('h1') # searches all H1 tags for 'my heading'
# or
# rendered.should contain('my string') # searches entire rendered string for 'my string'
class Within
def initialize(expected, css_selector)
@expected = expected
@mattsnyder
mattsnyder / authentication_helpers.rb
Created June 17, 2011 14:07
Easy faking of user authentication in RSpec when using Devise
module AuthenticationHelpers
# Example usage: login mock_user(Editor)
def login(user)
request.env['warden'] = mock(Warden,
:authenticate => user,
:authenticate! => user)
end
def mock_user(type, stubs={})
mock_model(type, stubs).as_null_object
@mattsnyder
mattsnyder / Prefer.rb
Created July 8, 2011 13:16
Offer up a replacement should the prefered value not be present
def Prefer(value)
if value.present? then
value
else
block_given? ? yield : NullObject.new
end
end
@mattsnyder
mattsnyder / roman_numeral_calculator_describe_block.rb
Created July 20, 2012 12:32
Example rewrite of describe block
describe "Converting integers to roman numerals" do
end
@mattsnyder
mattsnyder / roman_numeral_custom_matcher.rb
Created July 20, 2012 12:41
Example custom matcher to use for testing roman numeral conversions
RSpec::Matchers.define :be_converted_to do |expected|
match do |actual|
@result = Calculator.convert(actual)
@result == expected
end
failure_message_for_should do
"Expected #{actual} to be converted to #{expected}, but got #{@result}"
end