This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#BEFORE | |
class Observer < ActiveModel::Observer | |
class_attribute :observed_methods | |
self.observed_methods = [].freeze | |
def initialize | |
super | |
observed_descendants.each { |klass| add_observer!(klass) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Captures $stdout and $stderr into strings: | |
# | |
# out, err = capture_io do | |
# warn "You did a bad thing" | |
# end | |
# | |
# assert_match %r%bad%, err | |
def capture_io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/unit' | |
MiniTest::Unit.autorun | |
class TestMeme < MiniTest::Unit::TestCase | |
def test_flunk | |
pid = fork do | |
exec("sleep 100") # firefox in reality | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/unit' | |
MiniTest::Unit.class_eval do | |
def self.autorun | |
at_exit { | |
next if $! # don't run if there was an exception | |
# the order here is important. The at_exit handler must be | |
# installed before anyone else gets a chance to install their | |
# own, that way we can be assured that our exit will be last |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Test::Unit::Extensions | |
module AssertDifferences | |
# assert_stable_count(Person) <=> assert_no_difference("Person.count") | |
def assert_stable_count(expression, &block) | |
assert_same_count(expressify_class(expression), &block) | |
end | |
# assert_removed(Person) <=> assert_difference("Person.count", -1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'bundler' | |
Bundler.setup(:default, :test) if defined?(Bundler) | |
require "selenium-webdriver" | |
require 'capybara/dsl' | |
Capybara.default_driver = :selenium | |
Capybara.default_selector = :css | |
Capybara.default_wait_time = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
rails_root = File.expand_path('../..', __FILE__) | |
watchr_file = File.join(rails_root, '.watchr') | |
watch( 'app/(.*)\.rb' ) {|md| FileUtils.touch(watchr_file) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
initializer :set_clear_dependencies_hook do | |
unless config.cache_classes | |
changed_at = Proc.new{ File.new(File.join(Rails.root, '.watchr')).mtime } | |
last_change = changed_at.call | |
ActionDispatch::Callbacks.before do | |
change = changed_at.call | |
if change > last_change | |
Rails.logger.info("DETECTED CHANGES") | |
last_change = change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inside = Proc.new{ puts 'inside' } | |
nested = [1,2,3].reverse.inject(inside) do |sum, obj| | |
Proc.new do |&inner| | |
puts obj | |
sum.call(&inner) | |
puts obj | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if defined?(Rails::Server) # rails s only (not in console) | |
fork do | |
exec("watchr", "script/touch.watchr") | |
end | |
end |
OlderNewer