[mocha-developer] Need some help in reducing my repetions in tests with Mocha

Jonathan Stott jonathan.stott at gmail.com
Sat May 3 16:23:48 EDT 2008

> Hi Jon,
> It's hard to give good advice because we are missing too many pieces  
> of information. For example, your test references both @base and  
> "good_response", neither of which are shown elsewhere. Also, without  
> your domain code it's hard to say what the best way to test it is.

Well, a good_response is just that. It's something the library is expecting from the server (else it will raise a BadResponse error) but otherwise it isn't actually that important to the method I'm testing.  (it's a stub which returns the minimum possible info)

Though I've just realised perhaps I should make it a mock and actually give it some expectations when I test the net interacting part. </digression>

@base is the actual thing I'm testing which has the code which makes the API request.

> But, not having enough information has never stopped me from giving my  
> opinion before...
> I looks to me like you should create smaller methods, if not a few  
> more classes depending on how much is going on. For example, you want  
> to test that the token is in the parameters, so why not create a  
> method that returns the url. If you have a method that returns the  
> url, then you can test that method in isolation.

There are actually some methods which are behind the query method (though not actually so fine grained/small as to have one which makes the URL) but they are currently all protected, since they should never need to be called in isolation, except if I wanted to test them ...

What is the best way of testing protected methods?  Or should I just make everything public?

> Cheers, Jay


More information about the mocha-developer mailing list