I wrote this up here: http://blog.steveklabnik.com/posts/2012-02-27-hypermedia-api-reading-list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSColor+Hex.h | |
// SoundCloud | |
// | |
// Created by Robert Böhnke on 4/1/11. | |
// Copyright 2011 Soundcloud Ltd. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Then /^"([^"]*)" should be set as "([^"]*)"$/ do |term, definition| | |
first(:xpath, "//dd[preceding-sibling::dt[.='#{term}']]").text. | |
should == definition | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'factory_girl' | |
require 'faker' #if needed | |
Dir[Rails.root.to_s + '/spec/factories/**/*.rb'].each {|file| require file } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sqlite> .mod col | |
sqlite> .headers on |
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").
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
OlderNewer