<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">"But otherwise, what exactly are you testing?" <br></blockquote>That's a great point. I don't want to be specing Rails if it is not easily separable for testing already. In theory, I would like to have true unit tests for my models. However, in practice, some of my models are coupled to some degree.
<br><br>Generally speaking, I prefer not to mock/stub Rails internals to test my app. I don't find mocking/stubbing *my* code -- that is fine with me. But the internals of Rails are *not* what I'm trying to test.
<br><br>In particular, I found that mocking/stubbing with has_many :through was far from simple. I fired up ruby-debug (highly recommended!) and everything, but realized it was too much effort and too little time. In this sense, my experience is probably similar to Scott's (above post).
<br><br>My Goal model, for example, checks to see how many Contributions it
has. It uses a has_many :through (hmt) association. Despite the
helpful words of some posters in this thread, I couldn't find a way to
effectively spec the hmt association. By the time I had stubbed out enough to make
it a true unit test, I was no longer testing what I wanted to test --
namely, that the association itself. <br>
<br>
Maybe this was a wake up call that there was not point in trying to
test that at a unit level? In any case, I've got some conditional
logic that connects with the association, so I definitely need to test
that, at least.<br><br>In the end, I just tested the "interaction" between models. In this folder, I test how models in my app work together. I didn't think these specs fit under 'model' because they are testing more than one model.
<br><br>So I put them in a new directory called 'model_integration' folder under the 'spec' directory. I came up with
this name on my own intuition, and I can't blame anyone else if this is
a bad idea. I wasn't sure if 'model_interaction' would have been a better name, but from what I gather, 'interaction' is a special term when it comes to testing. Suggestions?<br><br>-DJ<br>