Avdi Grimm wrote:
> 1. Why are we suddenly discussing a two year old post here? Clue me in.

My apologies!  It appeared at the top of my list feed and I neglected to 
check the date.  I'm not sure why it appeared at the top of my feed.

[...]
> But briefly, I'll say this: if you are including the DB, you aren't Unit 
> Testing. Period. Your tests might be *useful* and *important*, but they 
> aren't Unit Tests. A lot of Rails practices, while overall encouraging 
> more TDD, have muddied the waters WRT to what is a Unit Test. 

Yeah, I'm aware of that.

> A Unit 
> test isolates a *single* object or method from *all* of its 
> collaborators, and tests the inputs of that object or method in a 
> vacuum. If it doesn't isolate, it's not a Unit Test.

And there's an argument to be made that since the AR framework is part 
of an AR class, it must be respected -- and hit *some* state-preserving 
DB-like thing -- to properly unit test an AR class.

> 
> Which, again, is not to say it's a bad test. These days I drive my app 
> development almost exclusively from high-level full-stack Cucumber 
> acceptance tests, and only drop down to the Unit level when there is 
> some particularly interesting/tricky logic to be described.

I do similarly.

> And 
> sometimes I write functional level tests that include the DB but not the 
> UI level. But I don't call them unit tests and I keep them separate from 
> my unit tests. If you are interested in this kind of Unit Test 
> discipline - which, when followed, tends to make for smaller, 
> tightly-cohesive objects - NullDB may be for you.

Got some sample code in this style?  I'd like to look at it, even though 
I think (a priori) that it is a recklessly dangerous way to test AR 
classes.  I just might learn something. :)

> Especially because it 
> enables you to test (for instance) logic in after_save hooks which would 
> otherwise force the DB to get involved.

I *want* the DB to get involved if I'm testing the DB lifecycle of my 
objects.

> 
> --
> Avdi

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to