Learning Ruby

Reference, Mnemonic & Ramblings

Takeaways From Course 3 - Part 1

These are some key takeaways from the 3rd course for me based on the reviews i received from the TAs for every module (aka Week).

This is my beginner-TDD phase, so a lot these pertain to that in general and RSpec in specific(!), since that is what will be used in the course as the testing framework.

Module 1

  • Show success or failure flash-messages when handling post requests to notify the user
  • Standard validations on a models attribute can be written in a single line, like this:
    validates :email, length: {minimum: 5}, uniqueness: true Whether it should be done or not depends on how much it affects readability
  • Why (it used to be necessary to) end a file with a blank line? Read here.

Module 2

  • As a beginner-TDDer,
    1. Start putting stuff in views assuming public interfaces of classes/models and Controller#actions. And then get into writing failing tests (first functional/controller and then unit/model).*
    2. Write spec titles for as many scenarios as you can think of starting with the most obvious ones through to edge cases, without over-analyzing it (you can always add more tests!).
    3. Start the red-green-refactor cycle in the same order.
    4. Do not test the code you do not own. For example, whether a GET request to books#index renders the "books/index.html.haml" template. That is pretty much Rails' responsibility!
  • Make sure the test setup is not too far from the action and assertion in a spec. This tends to happen when using let, let!, before in RSpec.
  • Loved the use of the Fabrication and Faker gems in generating test data!

* Let BDD drive TDD: Outside-in development comes more naturally to me. Here's a great article about this approach.

comments powered by Disqus