Skip to content

Instantly share code, notes, and snippets.

original_process = Process.pid
SimpleCov.at_exit do
if Process.pid == original_process
SimpleCov.result.format!
end
end
@myronmarston
myronmarston / bundle-standalone-repro.sh
Created January 31, 2014 22:07
Repro script for bundle install --standalone failure
#!/bin/bash
set -ex
mkdir -p /tmp/repro-bundle-standalone-failure
cd /tmp/repro-bundle-standalone-failure
bundle env
# Bundler 1.5.2
# Ruby 1.9.3 (2013-06-27 patchlevel 448) [x86_64-darwin12.4.0]
@myronmarston
myronmarston / queues.rb
Last active January 4, 2016 01:39 — forked from dlecocq/queues.rb
➜ 8549841 git:(master) ✗ ruby queues.rb
Popping before put
popped job:
popped job:
popped job:
popped job:
popped job:
popped job:
popped job:
popped job:
@myronmarston
myronmarston / in_sub_process.rb
Created January 15, 2014 19:06
in_sub_process for test isolation
module InSubProcess
if Process.respond_to?(:fork) && !(RUBY_PLATFORM == 'java' && RUBY_VERSION == '1.8.7')
# Useful as a way to isolate a global change to a subprocess.
def in_sub_process
readme, writeme = IO.pipe
pid = Process.fork do
exception = nil
begin
yield
@myronmarston
myronmarston / message_specific_error_classifier.rb
Created January 1, 2014 08:13
message_specific_error_classifier.rb
# Generates a module that can be used in a rescue clause
# in order to rescue errors that match a specific class
# and message. This is useful when there is a generic
# error like `Sequel::Mysql2Error` that we want to only rescue
# some instances of based on the message.
module MessageSpecificErrorClassifier
def self.new(root_error, fragment)
Module.new do
define_singleton_method(:fragment) { fragment }
define_singleton_method(:root_error) { root_error }
@myronmarston
myronmarston / foo.rb
Last active December 29, 2015 03:39
There are some pretty bizarre things you can do with `method_missing` and public/private. But don't.
class Foo
def call_private_bar
bar
end
private
def bar
:private_bar
end
@myronmarston
myronmarston / Rakefile
Created November 15, 2013 20:42
In reply to: https://twitter.com/avdi/status/401429567250108416 Curious: how do you deal with app Rakefiles that you use in production but without the testing gems being available in prod? Gists welcome.
begin
require 'rspec/core/rake_task'
rspec_loaded = true
rescue LoadError
rspec_loaded = false
puts "\nThe spec tasks were not defined since rspec could not be loaded.\n\n"
end
if rspec_loaded
# define the tasks that depend on RSpec
@myronmarston
myronmarston / gc_signal.rb
Created October 17, 2013 18:11
GC signal for Qless
trap('USR1') do
before_status = File.read("/proc/#{Process.pid}/status")
before_time = Time.now
GC.start
after_time = Time.now
duration_in_ms = ((after_time - before_time) * 1000).to_i
after_status = File.read("/proc/#{Process.pid}/status")
log(:error, "Ran GC. Took #{duration_in_ms} ms. Before proc status: #{before_status}. After proc status: #{after_status}")
end
@myronmarston
myronmarston / ruby-1.8.7-build.log
Created September 25, 2013 12:49
Output when trying `ruby-install ruby 1.8`
➜ ~ ruby-install ruby 1.8
>>> Installing ruby 1.8.7-p374 into /Users/myron/.rubies/ruby-1.8.7-p374 ...
>>> Installing dependencies for ruby 1.8.7-p374 ...
Warning: openssl-1.0.1e already installed
Warning: readline-6.2.4 already installed
Warning: libyaml-0.1.4 already installed
Warning: gdbm-1.10 already installed
Warning: libffi-3.0.13 already installed
>>> Downloading http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p374.tar.bz2 into /Users/myron/src ...
% Total % Received % Xferd Average Speed Time Time Time Current

TL; DR: "mock" and "stub" were the common terminology when RSpec's API was first created but we've realized that using them to create fake objects causes confusion and that double is a much better term.

I wasn't around when RSpec's original APIs were created, so this is a bit of guess work, but here's my understanding.

When RSpec's mocking API was first created, the two common terms used for what we now commonly call "test doubles" were mocks and