Skip to content

Instantly share code, notes, and snippets.

View kyamaguchi's full-sized avatar

kyamaguchi kyamaguchi

View GitHub Profile
@kyamaguchi
kyamaguchi / gist:3227656
Created August 1, 2012 15:09
A sample of spec_helper with spork
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
@kyamaguchi
kyamaguchi / gist:3227620
Created August 1, 2012 15:06
RSpec stub
# Default
Hoge.any_instance.stub(:save).and_return(false)
Hoge.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
# mocha
Hoge.any_instance.stubs(:save).returns(false)
Hoge.any_instance.expects(:update_attributes).with({'these' => 'params'})
# spec_helper for mocha
RSpec.configure do |config|
@kyamaguchi
kyamaguchi / .rac
Created July 27, 2012 14:37
A sample of Rails Apps Composer
recipes:
- action_mailer
- active_admin
- activerecord
- add_user
- capybara
- cleanup
- devise
- extras
- git
@kyamaguchi
kyamaguchi / gist:2929788
Created June 14, 2012 11:35
Email settings with MockSMTP
# config/initializers/setup_email.rb
if Rails.env.development?
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 1025,
:domain => "localhost"
}
end
@kyamaguchi
kyamaguchi / gist:2862510
Created June 3, 2012 07:50
extending drag with capybara
module CapybaraExtension
def drag_by(right_by, down_by)
base.drag_by(right_by, down_by)
end
end
module CapybaraSeleniumExtension
def drag_by(right_by, down_by)
resynchronize { driver.browser.action.drag_and_drop_by(native, right_by, down_by).perform }
end
@kyamaguchi
kyamaguchi / gist:2834504
Created May 30, 2012 08:17
Test with asset pipeline
### config/environments/test.rb
...
# Add assets settings to be identical to production env
# Using
if ENV['ASSETS']
puts "ENV['ASSETS'] is given. Set asset pipeling configurations."
# Compress JavaScripts and CSS
config.assets.compress = true
@kyamaguchi
kyamaguchi / gist:2832315
Created May 30, 2012 01:32
Capistrano log recipes
namespace :log do
desc "tail production log files"
task :tail, :roles => :app do
run "tail -fn 100 #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
trap("INT") { puts 'Interupted'; exit 0; }
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
@kyamaguchi
kyamaguchi / gist:2832297
Created May 30, 2012 01:31
Capistrano variables
# Ruby 1.8.7
def show_capistrano_variables(exec_proc = false)
report = []
require 'active_support/ordered_hash'
require 'active_support/core_ext/hash/keys'
report << "="*20 + " @variables " + "="*20
ActiveSupport::OrderedHash.new.merge(instance_variable_get("@variables")).stringify_keys.sort.each do |k,v|
next if %w{password}.include?(k)
@kyamaguchi
kyamaguchi / gist:2832280
Created May 30, 2012 01:29
Capistrano rake recipes
# [NOTE!] namespace :rake cannot be used because 'rake' is already used as capistrano variable.
# #{rake} will be #<Capistrano::Configuration::Namespaces::Namespace:0x103abdf48> and command will abort if namespace :rake is used.
namespace :raketask do
desc "Show available rake tasks($ cap staging raketask:show_tasks)."
task :show_tasks do
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} -T"
end
desc "Run a task on a remote server($ cap staging raketask:invoke task=a_certain_task)."
@kyamaguchi
kyamaguchi / gist:2832268
Created May 30, 2012 01:28
Capistrano deploy recipes
# Deploy tasks for Passenger
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end