Created
May 8, 2009 03:21
-
-
Save snusnu/108591 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "dm-core" | |
require "spec" | |
DataMapper.setup(:default, "sqlite3::memory:") | |
class Person | |
include DataMapper::Resource | |
property :id, Serial | |
before :save, :shower | |
after :save, :shave | |
def shower | |
@showered = true | |
end | |
def shave | |
@shaved = true | |
end | |
def showered? | |
@showered | |
end | |
def shaved? | |
@shaved | |
end | |
end | |
describe "Hooking Resource#save" do | |
before(:all) do | |
DataMapper.auto_migrate! | |
end | |
describe "when the hooked method DOES CALL super" do | |
before(:each) do | |
class Person | |
def save(context = nil) | |
super(context) | |
end | |
end | |
end | |
it_should_behave_like "hooks" | |
end | |
describe "when the hooked method DOES NOT CALL super" do | |
before(:each) do | |
class Person | |
def save(context = nil) | |
true | |
end | |
end | |
end | |
it_should_behave_like "hooks" | |
end | |
describe "hooks", :shared => true do | |
it "should preserve established before and after hooks" do | |
p = Person.new | |
p.should_not be_showered | |
p.should_not be_shaved | |
p.save | |
p.should be_showered | |
p.should be_shaved | |
end | |
end | |
end | |
# mungo:Desktop snusnu$ spec -c -f -s freak.rb | |
# | |
# Hooking Resource#save when the hooked method DOES CALL super | |
# - should preserve established before hooks | |
# | |
# Hooking Resource#save when the hooked method DOES NOT CALL super | |
# - should preserve established before hooks (FAILED - 1) | |
# | |
# 1) | |
# 'Hooking Resource#save when the hooked method DOES NOT CALL super should preserve established before hooks' FAILED | |
# expected showered? to return true, got nil | |
# ./freak.rb:76: | |
# | |
# Finished in 0.007412 seconds | |
# | |
# 2 examples, 1 failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment