Traversing the Internets

Web Development in NYC

Flatiron School Day Twenty Three - RSpec Musings

| Comments

Todays post is going to be short. I’m going to write down some thoughts about RSpec and writing tests.

Write out what you want your tests to do without worrying about the actual syntax for the tests first. Statements like “it ‘should do whatever this test should do’” do can be followed with pending on the next line. This allows you to write out all of the ideas with what you would like your code to do without having to worry about any syntax yet. You can then impliment tests as you’re comfortable and write the corresponding code to pass them when the tests are ready.

Sometimes it’s helpful to write out skeleton tests, to describe what features a given unit of work should DEFINITELY have without worrying too much about potential features or tasks that it may need further down the line. Once you get the basics built out on your files when you come across new functionality that is needed you can go back and add tests and then add the code to get those to pass. This approach can save some time as you won’t need to try and brainstorm every feature you might come across and can instead focus on making sure your tests are good and that your code passes them. You can always add more tests later

With the level of complexity of our current projects, writing tests often feels very frustrating. It feels like spending a lot of time writing out very basic things about the code when we could be actually writing the program. Intellectually I’m aware that this work will pay off down the line as projects become more complex, so in the meantime I need to keep reminding myself that it’s not slowing us down, it’s preparing us for things to come.

Comments