Skip to content

Instantly share code, notes, and snippets.

View gist:452792
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
View Setup AMI for Rails
-- 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 Apr 15, 2011
Contain Within Matcher for use in your view specs. Faster than css_select and assert_select.
View contain_within_matcher.rb
# 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 Jun 17, 2011
Easy faking of user authentication in RSpec when using Devise
View authentication_helpers.rb
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 Jul 8, 2011
Offer up a replacement should the prefered value not be present
View Prefer.rb
def Prefer(value)
if value.present? then
value
else
block_given? ? yield : NullObject.new
end
end
View roman_numeral_calculator_describe_block.rb
describe "Converting integers to roman numerals" do
end
@mattsnyder
mattsnyder / converting_roman_numerals_spec.rb
Created Jul 20, 2012
example specs for converting roman numerals
View converting_roman_numerals_spec.rb
describe "Converting integers to roman numerals" do
describe "with simple conversions" do
Then { 1.should be_converted_to 'I' }
Then { 5.should be_converted_to 'V' }
Then { 10.should be_converted_to 'X' }
end
describe "with additive conversions" do
Then { 3.should be_converted_to 'III' }
@mattsnyder
mattsnyder / roman_numeral_calculator_spec.rb
Created Jul 20, 2012
Example of classname in description block
View roman_numeral_calculator_spec.rb
describe RomanNumeralCalculator do
describe "with simple conversions" do
Then { RomanNumeralCalculator.convert(1).should == 'I' }
end
end
@mattsnyder
mattsnyder / roman_numeral_custom_matcher.rb
Created Jul 20, 2012
Example custom matcher to use for testing roman numeral conversions
View roman_numeral_custom_matcher.rb
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
@mattsnyder
mattsnyder / phone_number.rb
Created Aug 23, 2012
Phone Number Generator
View phone_number.rb
def phone_number
o = [(0..9)].map{|i| i.to_a}.flatten;
(0..9).map{ o[rand(o.length)] }.join
end