Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for compiling the quotes from 2007. It is fun to look back.</p> <p>My current testing approach is covered in <a href="http://railscasts.com/episodes/275-how-i-test">this RailsCasts episode</a> which I have been quite happy with. In summary I have two levels of tests.</p> <ul> <li><p><strong>High level:</strong> I use request specs in RSpec, Capybara, and VCR. Tests can be flagged to execute JavaScript as necessary. Mocking is avoided here because the goal is to test the entire stack. Each controller action is tested at least once, maybe a few times.</p></li> <li><p><strong>Low level:</strong> This is where all complex logic is tested - primarily models and helpers. I avoid mocking here as well. The tests hit the database or surrounding objects when necessary.</p></li> </ul> <p>Notice there are no controller or view specs. I feel these are adequately covered in request specs.</p> <p>Since there is little mocking, how do I keep the tests fast? Here are some tips.</p> <ul> <li><p>Avoid excessive branching logic in the high level tests. Any complex logic should be moved to the lower level.</p></li> <li><p>When generating records (such as with Factory Girl), use <code>build</code> first and only switch to <code>create</code> when necessary.</p></li> <li><p>Use <a href="http://railscasts.com/episodes/264-guard">Guard</a> with <a href="http://railscasts.com/episodes/285-spork">Spork</a> to skip the Rails startup time. The relevant tests are often done within a few seconds after saving the file. Use a <code>:focus</code> tag in RSpec to limit which tests run when working on a specific area. If it's a large test suite, set <code>all_after_pass: false, all_on_start: false</code> in the Guardfile to only run them all when needed.</p></li> <li><p>I use multiple assertions per test. Executing the same setup code for each assertion will greatly increase the test time. RSpec will print out the line that failed so it is easy to locate it.</p></li> </ul> <p>I find mocking adds brittleness to the tests which is why I avoid it. True, it can be great as an aid for OO design, but in the structure of a Rails app this doesn't feel as effective. Instead I rely heavily on refactoring and let the code itself tell me how the design should go.</p> <p>This approach works best on small-medium size Rails applications without extensive, complex domain logic.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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