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 "sequel" | |
# Connect to the DB to make sequel happy. It expects a DB connection when you subclass Sequel::Model | |
DB = Sequel.sqlite | |
# Use the module to avoid naming collisions with other specs. | |
module LearnSequelModelSpec | |
# Where can I safely declare this class without specifying | |
# the database for it?! |
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 'rubygems' | |
require 'httpclient' | |
require 'vcr' | |
require 'savon' | |
require 'test/unit' | |
VCR.config do |c| | |
c.cassette_library_dir = 'fixtures/cassettes' | |
c.stub_with :webmock | |
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
module Starfish | |
module AwsS3 | |
# S3Archive initializes and provides archival-oriented access to an S3 bucket. | |
class S3Archive | |
def initialize | |
config = YAML.load_file("#{File.expand_path('~')}/.ec2/aws-secret.yml") | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => config['aws']['access_key'], |
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
# Toss this in your ~/.irbrc file for a convenient way | |
# to peruse Ruby source code in TextMate. | |
# | |
# Use in irb like so: | |
# | |
# >> require 'active_record' | |
# >> ActiveRecord::Base.source_for_method(:create) | |
class Object | |
def source_for_method(method) |
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
day = case self.type | |
when 'fast' then :fast_completion_day | |
when 'super_fast' then :super_fast_completion_day | |
when 'ludicrous' then :ludicrous_completion_day | |
else :budget_completion_day | |
end | |
self.value = Increment.first.max_hours * Incrementor.first.send(day) |
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
the request body |
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
module ModuleStubbing | |
def stubbed_modules | |
@stubbed_modules ||= [] | |
end | |
def stub_module(full_name) | |
most_shallow_stubbed_module = nil | |
full_name.to_s.split(/::/).inject(Object) do |context, name| | |
begin |
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
def stub_model(model_name) | |
stub_class model_name, ActiveRecord::Base | |
end | |
def stub_class(class_name, super_class = Object) | |
stub_module class_name, Class.new(super_class) | |
end | |
def stub_module(module_name, object = Module.new) | |
module_name = module_name.to_s.camelize |
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
# My normal approach: | |
require './path/to/my_class' | |
describe MyClass do | |
let(:my_class) { MyClass.new } | |
describe '#add_widget' do | |
it "makes a widget using OtherClass" do | |
other_class = fire_replaced_class_double("OtherClass") | |
other_class.should_receive(:make_widget!) |
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
describe "#mentions_story?" do | |
subject { described_class.new(file) } | |
let(:file) { "COMMIT_EDITMSG" } | |
def set_file_contents(text) | |
File.stub(:read).with(file) { example_commit_message(text) } | |
end | |
context "commit message contains the special Pivotal Tracker story syntax" do |
OlderNewer