Skip to content

Instantly share code, notes, and snippets.

TL;DR

Both methods are nearly identical in perf. Differences are due more to underlying forwarded messages' implementation than how the message forwarding is defined.

Summary

Error rates between each type, for the most part, negate any real ranking. A real stat analysis would be necessary to make a real determination.

Grouped by Command style:

@cupakromer
cupakromer / broken_session
Created September 30, 2014 20:34
Bundler binstubs + standalone problem
# With a clean project setup
$ bundle --binstubs --standalone
$ bundle binstubs rspec-core
$ cat bin/rspec
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
@cupakromer
cupakromer / gist:68c6ad077d5d535211f4
Created August 18, 2014 21:14
Generatron slide updates for RSpec 3 goodies (https://github.com/jessitron/generatron)

Some suggested updates to the slides in https://github.com/jessitron/generatron. These suggestions are based off of the array of built-in matchers that RSpec 3 provides (https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/built-in-matchers). As well as the composability / compounding features now available: http://myronmars.to/n/dev-blog/2014/01/new-in-rspec-3-composable-matchers

Slide 24

expect(influence.relevance).to (be <= 100).and (be >= 0)

You can also just make this a range matcher:

@cupakromer
cupakromer / gist:234e5468586c5aa3daa3
Created August 4, 2014 16:28
Check raise error with backtrace
def capture_backtrace(with_error: StandardError, &action)
action.call
:no_error_raised
rescue with_error => e
e.backtrace
end
# This fails if SocketError is not raised,
# or if the message doesn't match
it "raises a socket error reporting the address info" do
@cupakromer
cupakromer / gist:fc5ccd67714c878dd5d8
Created July 25, 2014 16:06
Sample model spec using RSpec 3.0 and Ruby 2.x
require 'rails_helper'
RSpec.describe User, type: :model do
def build_valid_user(opts = {})
valid_opts = {
name: "Example User",
email: "user@example.com",
password: "foobar",
password_confirmation: "foobar",
@cupakromer
cupakromer / spec-domain-exportable_widget.rb
Created July 18, 2014 21:54
Trying out some new RSpec `shared_example` ideas
require 'domain/exportable_widget'
require 'support/preconditions'
RSpec.describe ExportableWidget do
# We don't know yet if we will have multiple exportable objects, but this
# is simply the documentation of our intended shared protocol if we do later.
shared_examples_for "an exportable" do
required_attribute :exportable
# As far as I was aware, symbol-to-proc was supposed to be roughly equivalent to:
#
# Proc.new { |v| v.send(self) }
#
# However, the following produces very odd results. Why?!?
[[3, 4], [5, 6], [3, 4], [5, 6]].each_with_index.map(&:first)
# => [[], [5], [3, 4], [5, 6]]
[[3, 4], [5, 6], [3, 4], [5, 6]].each_with_index.map{ |x| x.first }
# => [3, 5, 3, 5]
@cupakromer
cupakromer / gist:974c6fb9d0d6de3c2a6e
Created July 15, 2014 21:59
Various way to test for monkey patching with RSpec 3's `instance_double`
class Calculator
def reduce(operator)
fail "You shouldn't be calling this directly!"
end
end
def uses_a_duck_type(calculation)
calculation.reduce(:+)
end
@cupakromer
cupakromer / gist:5037f32312e75413e645
Last active August 29, 2015 14:03
Command Line Tricks

Command Line Tricks

  • !! Repeat Previous Command
  • !-1 Repeat Previous Command
  • !-2 Repeat 2nd Previous Command
  • !ps Execute Previous Command STARTING WITH ps
  • !^ First Argument From Previous Command
  • !:2 2nd Argument From Previous Command
  • !$ Last Argument From Previous Command
  • !!:$ Last Argument From Previous Command
gem 'jekyll', '~> 2.0.0.alpha'
gem 'nokogiri'
gem 'redcarpet'
gem 'rouge'