See below test.
a
a
a
a
# Show progress on rake task | |
def progress(char = '.') | |
STDOUT.write char | |
STDOUT.flush | |
end | |
ActiveRecord::Migration.say_with_time "Something" do |
# 10MB毎に10ファイルをローテートする。 | |
config.logger = Logger.new(config.log_path, 10, 10.megabytes) |
See below test.
a
a
a
a
diff --git a/config/boot.rb b/config/boot.rb | |
index dd5e3b6..9ee835a 100644 | |
--- a/config/boot.rb | |
+++ b/config/boot.rb | |
@@ -106,5 +106,19 @@ module Rails | |
end | |
end | |
+class Rails::Boot | |
+ def run |
# selenium-webdriver (2.12.2) (with rails3) | |
def assert_confirmation(message, choice = 'ok') | |
if selenium? | |
assert_equal message, page.driver.browser.switch_to.alert.text | |
if choice == 'ok' | |
page.driver.browser.switch_to.alert.accept | |
elsif choice == 'cancel' | |
page.driver.browser.switch_to.alert.dismiss | |
end |
# spec/support/bindaddress.rb | |
# Equivalent to $ rails server -b 127.0.0.1 | |
require 'webrick' | |
module Rack | |
module Handler | |
class WEBrick | |
def self.run(app, options={}) | |
options[:BindAddress] = '127.0.0.1' |
# spec/support/selenium_chromedriver.rb | |
Capybara.register_driver :selenium do |app| | |
# http://code.google.com/p/chromedriver/downloads/list | |
# sudo mv ~/Downloads/chromedriver /usr/bin/ | |
Capybara::Selenium::Driver.new(app, :browser => :chrome) | |
end |
# spec/support/detect_translation_missing.rb | |
module TranslationMissingDetector | |
module Capybara::Node::Finders | |
alias_method :find_original, :find | |
def find(*args) | |
begin | |
m = session.body.match(/translation[_ ]missing[^<]+/) | |
puts ["="*80, m[0], '', caller].join("\n")+"\n\n" if m |
# Could be placed in spec_helper.rb | |
# Requiring foo.rake in this example. | |
def run_foo_bar(arg) | |
require 'rake' | |
@rake = Rake::Application.new | |
Rake.application = @rake | |
Rake.application.rake_require "lib/tasks/foo" | |
Rake::Task.define_task(:environment) | |
silence do |
# http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-values | |
# http://rxr.whitequark.org/rubinius/source/kernel/common/hash18.rb | |
class Hash | |
def deep_values | |
ary = [] | |
each_value do |value| | |
if value.is_a? Hash | |
ary += value.deep_values | |
elsif value.is_a? Array |