Skip to content

Instantly share code, notes, and snippets.

View ClayShentrup's full-sized avatar
🏗️
🗳️🌱🌷🌐🏗️🏓☢️

Clay Shentrup ClayShentrup

🏗️
🗳️🌱🌷🌐🏗️🏓☢️
  • portland, oregon
View GitHub Profile
@ClayShentrup
ClayShentrup / names_for_let_object.rb
Last active June 23, 2016 00:51
names_for_let_objects 2
module NamesForLetObject
def names_for_let_objects(objects)
objects.map { |object| name_for_let_object(object) }
end
def name_for_let_object(object)
__memoized.instance_variable_get(:@memoized).key(object)
end
end
RSpec.shared_examples('a foreign_key constraint association') do
specify do
expect do
build(described_model, "#{association}_id" => 0).save(validate: false)
end.to raise_error(ActiveRecord::InvalidForeignKey)
end
end
@ClayShentrup
ClayShentrup / mock_clock.js
Created August 2, 2016 04:23
Stubbing Jasmine time
'use strict';
beforeEach(function () {
jasmine.clock().install();
jasmine.clock().mockDate(
new Date(2015, 4, 20)
);
});
afterEach(function () {
@ClayShentrup
ClayShentrup / vcr_setup.rb
Created August 11, 2016 23:05
vcr_setup.rb
# frozen_string_literal: true
require('vcr')
VCR.configure do |config|
config.cassette_library_dir = 'spec/cassettes'
config.hook_into :webmock
config.configure_rspec_metadata!
config.ignore_localhost = true
# Don't change this here! Instead, to record an initial cassette,
@ClayShentrup
ClayShentrup / ajax.js
Last active September 20, 2016 17:53
Jasmine spec helper basics
App.testHelpers.stubAjaxRequestWithData = function (requestURL, data, status) {
jasmine.Ajax.stubRequest(requestURL)
.andReturn({
status: status,
responseText: data,
contentType: 'text/html',
});
};
App.testHelpers.stubSuccessfulAjaxRequestWithData =
@ClayShentrup
ClayShentrup / shock.rb
Last active December 29, 2017 22:32
Sandi Metz COC
# Source: https://www.youtube.com/watch?v=f5I1iyso29U&t=23m44s
class Shock
def cost(type)
case type
when :front
FrontShockCost.new.compute
when :rear
RearShockCost.new.compute
when :lefty
LeftyShockCost.new.compute
shock_cost_class_map = {
front: FrontShockCost,
lefty: LeftyShockCost,
rear: RearSHockCost,
}
shock_cost_class = shock_cost_class_map.fetch(type, ShockCost)
shock_cost_class.new.compute
# frozen_string_literal: true
require('method_object')
# Handles the measurement year window, including scopes to allow querying of QDM
# models within specified date ranges relative to the measurement year.
MeasurementYear = Struct.new(:program) do
def initialize(program:)
super(program)
end
@ClayShentrup
ClayShentrup / alias_matchers.md
Created December 12, 2017 20:14 — forked from JunichiIto/alias_matchers.md
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
before(:each) do
ENV['SITE_DOMAIN'] = 'periscopedata.com'
end
after(:each) do
ENV.delete('SITE_DOMAIN')
ActionMailer::Base.deliveries.clear
end
def send_queued_mail_and_expect_subject_to_be(expected_subject)