Skip to content

Instantly share code, notes, and snippets.

Aaron Kromer cupakromer

Block or report user

Report or block cupakromer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cupakromer
cupakromer / broken_session
Created Sep 30, 2014
Bundler binstubs + standalone problem
View broken_session
# 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.
#
View gist:68c6ad077d5d535211f4

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 Aug 4, 2014
Check raise error with backtrace
View gist:234e5468586c5aa3daa3
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 Jul 25, 2014
Sample model spec using RSpec 3.0 and Ruby 2.x
View gist:fc5ccd67714c878dd5d8
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 Jul 18, 2014
Trying out some new RSpec `shared_example` ideas
View spec-domain-exportable_widget.rb
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
View gist:ad3619347b4de978e9fa
# 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 Jul 15, 2014
Various way to test for monkey patching with RSpec 3's `instance_double`
View gist:974c6fb9d0d6de3c2a6e
class Calculator
def reduce(operator)
fail "You shouldn't be calling this directly!"
end
end
def uses_a_duck_type(calculation)
calculation.reduce(:+)
end
View gist:5037f32312e75413e645

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
View Gemfile
gem 'jekyll', '~> 2.0.0.alpha'
gem 'nokogiri'
gem 'redcarpet'
gem 'rouge'
@cupakromer
cupakromer / gist:023278290dddebd785a6
Last active Aug 29, 2015
"class" methods in Ruby
View gist:023278290dddebd785a6
class Book
# This is a "class" method
def Book.catch_em_all
"I'm sorry, you can't do that Dave"
end
# This is also a "class" method, since "self" right now is the
# Class object instance for this "class"
def self.bind_it(spell)
"We're still working on binding books with spell."
You can’t perform that action at this time.