Skip to content

Instantly share code, notes, and snippets.

# RAILSLOVE.com template
#
# with help and ideas from:
# http://gist.github.com/33337 By Peter Cooper
# http://github.com/jeremymcanally/rails-templates/tree/master/suspenders.rb Suspenders by Thoughtbot Nathan Esquenazi
if yes?("symlink local rails copy to vendor?")
path = ask("what's the directory of your local rails copy?")
inside('vendor') { run "ln -s #{path} rails" }
require 'cucumber/rake/task'
namespace :cucumber do
Cucumber::Rake::Task.new(:webrat) do |t|
t.fork = true # Explicitly fork for cucumber 0.3.4 and rails
t.cucumber_opts = "--format progress"
t.step_list = %w{features/support/env.rb features/support/webrat.rb features/step_definitions}
t.feature_list = %w{features/webrat}
end
task :webrat => 'db:test:prepare'
module SimpleCachingTTL
CACHETIME = 24 * 3600 # Once per day
def cache(text, path)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') { |f| f.write( text ) }
text
end
@pacoguzman
pacoguzman / snippet_backend.rb
Created July 10, 2009 07:51
I18n that include pluralization rules for spanish within Rails - http://www.viget.com/extend/rails-internationalization-and-tu/
module I18n
module Backend
class SnippetBackend < Simple
protected
def init_translations
load_translations(*I18n.load_path.flatten)
load_translations_from_database
@initialized = true
end
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
# download, from_repo, and commit_state methods swiped from
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
# paste into .irbrc
require 'benchmark'
def time(&block)
result = nil
Benchmark.bm do |bm|
bm.report { result = yield }
end
result
Then /^I should see a form for "(.+)" containing (.+) fields$/ do |object, methods|
fields = methods.scan(/(\w+)(?:,|\sand\s|\s)?/).flatten
response.should have_selector(:form) do |form|
fields.each do |field|
form.to_s.should have_selector("input", :id => "#{object}_#{field}")
end
end
end
@pacoguzman
pacoguzman / env.rb
Created August 8, 2009 13:50 — forked from bmabey/env.rb
require 'rubygems'
require 'spork'
Spork.prefork do
# Sets up the Rails environment for Cucumber
ENV["RAILS_ENV"] ||= "cucumber"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'webrat'
@pacoguzman
pacoguzman / gist:166362
Created August 12, 2009 07:29
balinterdi_cucumber_flavor
# Sets up a Rails app with Cucumber (Rspec, Webrat, Factorygirl),
# Authlogic and Haml
# Also copies polished(?) config files and some basic step definitions
gem "rspec", :version => ">= 1.2.6", :lib => 'spec'
gem "rspec-rails", :version => ">= 1.2.6", :lib => 'spec/rails'
gem "cucumber", :version => ">= 0.3.9"
gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => "http://gems.github.com"
gem "webrat", :version => ">= 0.4.3"
gem "Selenium", :version => ">= 1.1.14", :lib => 'selenium'