Skip to content

Instantly share code, notes, and snippets.

View jackphelps's full-sized avatar

Jack Phelps jackphelps

View GitHub Profile
@jackphelps
jackphelps / 1_intro_to_subject.rb
Created January 12, 2016 16:10 — forked from knzai/1_intro_to_subject.rb
A pattern for testing class methods in ruby with rspec explicit subjects
# RSpec's subject method, both implicitly and explicitly set, is useful for
# declaratively setting up the context of the object under test. If you provide a
# class for your describe block, subject will implicitly be set to a new instance
# of this class (with no arguments passed to the constructor). If you want
# something more complex done, such as setting arguments, you can use the
# explicit subject setter, which takes a block.
describe Person do
context "born 19 years ago" do
subject { Person.new(:birthdate => 19.years.ago }
it { should be_eligible_to_vote }
@jackphelps
jackphelps / Rakefile
Last active August 29, 2015 14:22 — forked from jimweirich/Rakefile
#!/usr/bin/env ruby
require 'rake/clean'
require 'rake/testtask'
task :default => [:spec, :test]
task :spec do
sh "rspec ."
end
@jackphelps
jackphelps / type.js
Created November 6, 2013 16:07 — forked from jonbretman/type.js
(function (root) {
var type = function (o) {
// handle null in old IE
if (o === null) {
return 'null';
}
// handle DOM elements