[Rspec-devel] RSpec mock ideas/bugs

Mikkel Garcia mikkel at shatteredruby.com
Mon Sep 11 04:54:19 EDT 2006

Hey guys,
I'm a big fan of what y'all are trying to do.  I've been running into  
a few issues with it, in the form of bugs(non-conformity) and ideas.

Conformity - mock objects
Mocks have a .nil? function
context "A mock" do
   specify "should have no responses to any events" do
     @object = mock(:object)
     @object.nil?            #Will not raise a mock unexpected  
message event
     @object.object_id       #Will raise a mock unexpected message event

Mocks returned by mocks expect an :instance_of call
context "A mock returning a mock" do
   specify "should not receive instance_of message" do
     player = mock(:player)
     arch_enemy = mock(:arch_enemy)
     # This mock fails with: Mock 'enemy' received unexpected message  
'instance_of?' with [<Array:Class>]

Mocks being substituted for real objects - True integration tests for  
free ?
Alot of the specs we are writing separate responsibilities among  
tightly coupled classes.  We are testing the individuality, but if we  
wanted to test the true integration of those classes we would  
probably have to create new specs.  How about, instead, creating mock  
objects from classes themselves and having a rake spec:integrate  
task.  This task would substitute the real classes for the mocks,  
which brings me to:

Mocks/stubs syntax
Let's say I have a Level object, and that is responsible for reading  
my map into the game.  I have an object in that map I want to test 
(err...spec).  Would something like this be feasible?
@level = Level.mock
@level = Level.mock(:null_object => true)

Or maybe I have a class that has a GUI portion, and I want to stub  
that function.
@level = Level.stub  #Keeps all the Level functionality and lets you  
stub things out

That way, if you do something like:
spec -integrate level_spec.rb
it could turn all mocks and stubs into real objects.

I'm really excited about the implications this has towards  
simplifying game design, and I'm hoping that it works well enough to  
replace Test::Unit for our 3d game framework, Shattered.

-Mikkel Garcia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-devel/attachments/20060911/9ac7fd0e/attachment.html 

More information about the rspec-devel mailing list