Skip to content

Instantly share code, notes, and snippets.

View sbellware's full-sized avatar

Scott Bellware sbellware

View GitHub Profile
class Object
def self.dirname
eval "File.expand_path(File.dirname(__FILE__))"
end
end
class Bar
end
puts Bar.dirname
require 'lib/plugin'
class Bar < Plugin
end
puts Bar.dirname
# in lib/plugin
class Plugin
def self.dirname
class BusinessEvent
def self.inherited(clazz)
subclasses << clazz
end
def self.subclasses
@@subclasses ||= []
end
end
class BusinessEvent
def self.subclasses
subclasses = []
ObjectSpace.each_object(Module) {|m| subclasses << m if m.ancestors.include? self and m != self}
subclasses
end
end
class OrderEvent < BusinessEvent
end
@sbellware
sbellware / layout_helper.rb
Created November 16, 2010 07:24
Table helpers for HAML
module LayoutHelper
def layout(options={}, &block)
options.prepend! 'layout', :class
capture_haml do
haml_tag(:table, options) do
haml_concat capture_haml(&block)
end
end
end
module RSpec
module Core
class ExampleGroup
alias_example_to :observe
end
module ObjectExtensions
alias_method :context, :describe
end
end
end
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'instructions'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
@sbellware
sbellware / gist:728575
Created December 4, 2010 22:56
Syntactic Sugar to Mimic Assert-Arrange-Act in RSpec 2 Without Test Spies
# sample class to mock and test against
class Thing
def foo
bar
end
def bar
end
end
@sbellware
sbellware / gist:728582
Created December 4, 2010 23:02
This Doesn't Work
# see: https://gist.github.com/728575
describe Thing do
concern { subject.foo }
it { should_have_received(:bar) }
end
@sbellware
sbellware / gist:728743
Created December 5, 2010 03:39
Implicit Expectations Work Differently
# See the spec report at: http://screencast.com/t/lzXadGVp
# sample class to mock and test against
class Thing
def foo
bar
end
def bar
end