On 19 Oct 2009, at 20:08, Matt Roberts wrote:

> What I think might be nice is some sort of follow up that's code- 
> based - a piece of code with some dependencies that needs testing..  
> Perhaps you could show the code run and pass, and then show just how  
> brittle the test is and how much of a PITA it is to set up, and then  
> show how the test can be improved by using a stub. Then get into  
> "advanced" usage by using a mock to test the behavoir... Just a  
> thought ;)

That's a nice idea - thanks for the suggestion Matt. It goes way  
beyond mocking into BDD though, although that's not necessarily a bad  
thing.  And I think some live code would get the point across much  
better than slides.  My experience of teaching BDD/RSpec that some  
things are "obvious" when you see them done right, but it's not until  
you come to play with things and try to change them that you realise  
exactly how everything behaves and why.

If anyone else wants to see this let me (or, more importantly, Will)  
know.  I might consider it some time in the future after I've  
recovered from this one =)


> As for the diference between mocks and stubs, its a source of  
> confusion for a lot of people I think, me included. I found this  
> artcile a little useful: 
> http://weblogs.asp.net/rosherove/archive/2007/09/16/mocks-and-stubs-the-difference-is-in-the-flow-of-information.aspx
>  
>  - its a .net blog but it illustrates the differences quite well to  
> me. I suppose its important to differenciate between mocks and stubs  
> as long as the testing/mocking/stubbing frameworks out there  
> differenciate, although I'm not sure what there is to be gained by  
> having 2 different terms, whats wrong with "there are mocks, oh and  
> by the way you can also test the expected behavoir with them" ?


Hmmm, maybe the communication issue with this is caused by the fact  
RSpec works at a lower level.  Sure, you have mock objects and stub  
objects, but more importantly you have stub methods and message  
expectations.  *Those* are the things that control information flow in  
RSpec.  You can set a stub or expectation on a mock object, a stub  
object, or a "real" object.  (Hell, you could use Object.new if you  
really wanted.)

I mean, if you write this code:

   m = mock("m")
   m.stub(:foo).and_return(1)
   m.should_receive(:bar).and_return("two")

have you written a mock or a stub object?

That diagram is a nice description of the extra information coming  
from a mock (message expectation).  But again, it's RSpec that  
verifies this.  You could argue that RSpec checking message  
expectations were met is no different than a developer checking the  
system has 5 users after adding a new one to the first four.  Which  
means I still believe mock objects and stub objects are the same thing  
(in RSpec).

Cheers
Ashley


-- 
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/








--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"NWRUG" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nwrug-members?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to