Skip to content

Instantly share code, notes, and snippets.

Myron Marston myronmarston

Block or report user

Report or block myronmarston

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
myronmarston / ways_to_use_vcr.rb
Created Apr 13, 2012
Ways to use VCR for a request made by a let block
View ways_to_use_vcr.rb
# 1) Use VCR.use_cassette in your let block. This will use
# the cassette just for requests made by creating bar, not
# for anything else in your test.
let(:foo) { VCR.use_cassette("foo") { create(:bar) } }
it "uses foo" do
# 2) Wrap the it block that uses #foo in VCR.use_cassette.
myronmarston / output
Created May 10, 2014
Demonstration of using built in matchers from within a custom matcher
View output
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
Using built in matchers from custom ones
fails when the word does not end with the given letter (FAILED - 1)
fails when the word does not start with the given letter (FAILED - 2)
can match properly
View increment_and_decrement.rb
module IncrementAndDecrement
def increment(&block)
matcher = change(&block).by(1), lambda do |desc|
desc.gsub("changed", "incremented").gsub("change", "increment")
def decrement(&block)
matcher = change(&block).by(-1)
myronmarston / without_foreign_keys.rb
Created Sep 6, 2014
Example of how to disable foreign keys for a particular context
View without_foreign_keys.rb
RSpec.shared_context "without foreign key constraints", :disable_foreign_keys do
def without_foreign_key_checks'SET foreign_key_checks = 0;')
ensure'SET foreign_key_checks = 1;')
around(:example) { |ex| without_foreign_key_checks(&ex) }
myronmarston /
Last active Dec 14, 2018
Explanation for why `its` will be removed from rspec-3

its isn't core to RSpec. One the of the focuses of RSpec is on the documentation aspects of tests. Unfortunately, its often leads to documentation output that is essentially lies. Consider this spec:

User =, :email)

describe User do
  subject {"bob") }
  its(:name) { should == "bob" }

I highly suspect that the RSpec core team all use black backgrounds in their terminals because sometimes the colors aren’t so nice on my white terminal

I certainly use a black background. I'm not sure about the other RSpec core folks. Regardless, if there are some color changes we can make that would make output look good on a larger variety of backgrounds, we'll certainly consider that (do you have some suggested changes?). In the meantime, the colors are configurable, so you can change the colors to fit your preferences on your machine. First, create a file at

View hamster_spec.rb
module Hamster
def self.vector(*args)
class Vector < ::Array
alias add <<
View x_spec.rb
require 'yaml'
class X
def self.y
RSpec.describe X do
it 'works' do
myronmarston / spec_helper.rb
Created May 28, 2017
How to make RSpec fail if anything outputs
View spec_helper.rb
RSpec::Matchers.define_negated_matcher :avoid_outputting, :output
RSpec.configure do |config|
config.around do |ex|
expect(&ex).to avoid_outputting.to_stdout.and avoid_outputting.to_stderr
myronmarston / subscription.rb
Created Mar 8, 2012
How we do migrations with Ripple
View subscription.rb
require 'versionable'
class Subscription
include Ripple::Document
include Versionable
current_schema_version 2
migrate_schema do |data|
self.schema_version = 2
You can’t perform that action at this time.