Skip to content

Instantly share code, notes, and snippets.

@cavalle
cavalle / warden.rb
Created August 25, 2010 10:46
Testing Warden/Devise with Steak
# Create a file `spec/acceptance/support/warden.rb' with the following
# contents:
Spec::Runner.configure do |config|
config.include Warden::Test::Helpers, :type => :acceptance
config.after(:each, :type => :acceptance) { Warden.test_reset! }
end
# Or, if you're using RSpec 2 / Rails 3, the contents should be the following
# instead:
@robb
robb / NSColor+Hex.h
Created April 1, 2011 14:57
NSColor+Hex
//
// NSColor+Hex.h
// SoundCloud
//
// Created by Robert Böhnke on 4/1/11.
// Copyright 2011 Soundcloud Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
@pat
pat / gist:1096339
Created July 21, 2011 01:43
Check definition pair in a definition list
Then /^"([^"]*)" should be set as "([^"]*)"$/ do |term, definition|
first(:xpath, "//dd[preceding-sibling::dt[.='#{term}']]").text.
should == definition
end
@equivalent
equivalent / factories_inside_rails_console.rb
Created November 10, 2011 18:44
use factories inside rails console
require 'factory_girl'
require 'faker' #if needed
Dir[Rails.root.to_s + '/spec/factories/**/*.rb'].each {|file| require file }
@blueheadpublishing
blueheadpublishing / erb_import_subtemplates.rb
Created December 6, 2011 19:00
ERB Subtemplating Script: Import ERB From Within ERB
# This script will take the file book.html.erb and parse it. When it encounters
# <%= import('your_file.html.erb') %> it will parse the file and stream
# it into the parent erb file.
require "erb"
class ErbImportSubtemplate
def self.import(file)
# Parse the source erb file
@flashingpumpkin
flashingpumpkin / ssh-host-complete.sh
Created December 8, 2011 14:26
Auto completing for some commands from your hosts file
#!/bin/bash
# Choose one
complete -W "$(grep -E '^[0-9]' /etc/hosts | awk '{ print $2 }')" ssh scp rsync ping
complete -W "$(grep -E '^ssh' ~/.bash_history | awk '{ print $2 }')" ssh scp rsync
complete -W "$(grep -E '^(\w)' ~/.ssh/known_hosts | awk '{ print $1 }' | sort -u | cut -d ',' -f 1)" ssh scp rsync ping
@typeoneerror
typeoneerror / blah.sqlite
Created January 19, 2012 19:12
making sqlite cli not suck
sqlite> .mod col
sqlite> .headers on
@abner
abner / minitest_spec_expectations.md
Created March 24, 2012 00:34 — forked from ordinaryzelig/minitest_spec_expectations.md
How to write MiniTest::Spec expectations

I'm a fan of MiniTest::Spec. It strikes a nice balance between the simplicity of TestUnit and the readable syntax of RSpec. When I first switched from RSpec to MiniTest::Spec, one thing I was worried I would miss was the ability to add matchers. (A note in terminology: "matchers" in MiniTest::Spec refer to something completely different than "matchers" in RSpec. I won't get into it, but from now on, let's use the proper term: "expectations").

Understanding MiniTest::Expectations

Let's take a look in the code (I'm specifically referring to the gem, not the standard library that's built into Ruby 1.9):

# minitest/spec.rb

module MiniTest::Expectations
@wojtekmach
wojtekmach / account_test.rb
Created May 3, 2012 09:45
Writing MiniTest extensions
require 'minitest/autorun'
module MiniTest::Assertions
def assert_changes(obj, method, exp_diff)
before = obj.send method
yield
after = obj.send method
diff = after - before
assert_equal exp_diff, diff, "Expected #{obj.class.name}##{method} to change by #{exp_diff}, changed by #{diff}"