Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is considered a good spec? Rspec examples for beginners
    primarykey
    data
    text
    <p><strong>What is considered a solid spec?</strong> </p> <p>This is what I find to be very abstract about testing. I'd be interested in the answer for this on models, controllers and whatever else can be tested. It would be cool to have a spec for a spec, you know what I mean?</p> <p>A model spec should (in order of priority and relevance):</p> <ol> <li>Test all methods?</li> <li>Test errors array?</li> <li>Test CRUD (and how)?</li> <li>What else?</li> </ol> <p>A controller / view spec should (in order of priority / relevance):</p> <ol> <li>Fill in the blank...</li> <li>?</li> </ol> <p>Would be great to expand this list of what a spec should and shouldn't contain.</p> <p>I'd also like to compile a list of tricks and suggestions as well. For example:</p> <p>The keyword "should" is sorta redundant.</p> <p>Example: </p> <p>this:</p> <pre><code>it "should be invalid without a firstname" </code></pre> <p>would be better as:</p> <pre><code>it "is invalid without a firstname" </code></pre> <p>Yet another trick, use expect instead of lambda for readability:</p> <pre><code>lambda { ... }.should be_valid </code></pre> <p>is more readable as:</p> <pre><code>expect { ... }.should be_valid </code></pre> <p>I am compiling a list of helpful articles on getting started and will share those in this post as they come along. Here are some that I'm finding particularly helpful as of now. (Feel free to post yours and I'll tack it on if it seems helpful).</p> <p><a href="http://everydayrails.com/2012/03/19/testing-series-rspec-models-factory-girl.html">http://everydayrails.com/2012/03/19/testing-series-rspec-models-factory-girl.html</a> <a href="http://nelvindriz.tumblr.com/post/835494714/rspec-best-practices">http://nelvindriz.tumblr.com/post/835494714/rspec-best-practices</a></p> <p>It would be great to have a list of projects where tests are implemented well. Since rspec is so readable (at least that's what everybody says), it would be great to get a list of links to projects that have great specs to read.</p> <p>"See the <a href="https://github.com/mongoid/mongoid/tree/v3.0.3/spec">Mongoid specs</a> for an example of good specs." -@yfeldblum (see answer below)</p> <p>Online you'll find a lot of articles describing unrealistic scenarios on how to test basic stuff, but beyond that you're sorta on your own. If I were to write an article on this topic I would just link to my tests (on github for example), then thoroughly annotate one or a few of those specs... this seems like the best way to write an article on rspec, in my opinion. I'd do it myself, but I'm not quite there yet. </p> <p>If you vote to close this, that's fine, just try to leave a comment or suggestion on where you think this post would belong. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload