Skip to content

Instantly share code, notes, and snippets.

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

Clay Shentrup ClayShentrup

🏗️
🗳️🌱🌷🌐🏗️🏓☢️
View GitHub Profile
@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 =
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
@ClayShentrup
ClayShentrup / car.rb
Last active April 22, 2017 17:45
Skipping ActiveRecord association validations in tests
class Car < ActiveRecord::Base
attr_accessor(:skip_association_presence_validations)
validates(:driver, presence: true, unless: :skip_association_presence_validations)
# creates driver_license_number method
delegate(:license_number, to: :driver, prefix: true)
end
@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
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)
@ClayShentrup
ClayShentrup / stub.go
Created November 3, 2013 00:40
Stubbing in Go (Golang)
package main
import (
"fmt"
"reflect"
"time"
)
func main() {
stubPrototype := func(in []reflect.Value) []reflect.Value {
@ClayShentrup
ClayShentrup / one.rb
Last active September 2, 2018 05:59
Three ways to do STI factories
# assets.rb
FactoryBot.define do
factory(:asset) do
# definition
end
end
# audio_assets.rb
FactoryBot.define do
factory(:audio_asset, parent: :asset, class: AudioAsset) do
apiVersion: apps/v1
kind: Deployment
metadata:
name: adama
spec:
selector:
matchLabels:
app: adama
replicas: 1
template: