Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

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?!
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
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'],
@myronmarston
myronmarston / gist:1046700
Created June 25, 2011 17:42 — forked from clarkware/gist:1046693
View Source for Ruby
# 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)
@myronmarston
myronmarston / dry.rb
Created August 18, 2011 21:13 — forked from Fluxx/dry.rb
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)
@myronmarston
myronmarston / module_stubbing.rb
Created December 22, 2011 07:05 — forked from justinko/gist:1509034
Avdi Grimm's creation, pulled from Objects on Rails
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
@myronmarston
myronmarston / gist:1684632
Created January 26, 2012 19:42 — forked from justinko/gist:1684051
Methods to aid in testing without loading the Rails environment
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
@myronmarston
myronmarston / my_class_spec.rb
Created March 4, 2012 22:44 — forked from pat/gist:1947369
Using rspec-fire?
# 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!)
@myronmarston
myronmarston / some_spec.rb
Created March 20, 2012 23:40 — forked from stevenharman/some_spec.rb
Using Rspec's "let" inside an "it" block. Crazy? Yes. Useful? Occasionally.
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