[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Snippet - assert_yin_yang

Phlip

11/10/2007 3:51:00 AM

Rubies:

This is a Rails assertion, but any project could use its concept.

It asserts that a Model value is one state before a block, and another
state after:

def assert_yin_yang(object, method, yin, yang, diagnostic = nil)
message = build_message(diagnostic, "<?>#<?>", object, method)
assert_equal yin, object.send(method), message
yield
object.reload
assert_equal yang, object.send(method), message
end

Detect something switched from false to true like this:

helmet = shrew.accessories.first

assert_yin_yang helmet, :active, false, true do
post :use, :id => helmet.id
end

Any tips welcome regarding making this more yin-yang-ey!

--
Phlip
http://c2.com/cgi/...