Vickerdoodle

thoughts, opinions, and random arts & crafts

Technology

RSpec Resources

January 13, 2019 · No comments

As some of you know, I recently started an apprenticeship as a Ruby on Rails software engineer. I came into this new job with very little experience in the backend, let alone Ruby, and absolutely no experience with testing. My manager has been incredible with providing me with opportunities and resources to learn (I’m now on a full time team at the company!)

One of the things that she was very adamant about was that we needed to be testing. Not only were we learning how to code an app in Ruby on Rails, but we also needed to be able to write tests for our code. When I first started out, I found that writing tests seemed even harder than actually building the app we were working on. I’d knock out the actual app code in a day or two, but then it’d take almost a week to figure out how to write the right test to make sure that code was right. At the time, it was a little frustrating and I often questioned what the point was. But now that I’m working in a larger company application, one with a codebase that’s touched every day by many other developers, I’ve gained a real appreciation for writing tests.

Why test?

As you add more and more onto your project, it becomes harder and harder to ensure that the entire project is still workable. If you have one page, it may be pretty easy to check if everything looks good. But what if you’ve got 100 pages? Are you going to go back through all 99 previous pages to make sure everything works when you add that 100th page? Probably not. That’s where having tests already written comes in handy. You can just run all the tests when you add your 100th page, and if you have a good amount of coverage, then you’ll know if everything still works, or if that one thing you wrote for the 100th page doesn’t agree with something you wrote a few months ago.

But more than just that, well-written tests are also very helpful for people you’re collaborating with or people who are just looking at your code. The great thing about RSpec is that it reads like a sentence. Someone with no background knowledge with your project can come in, read your tests, and know exactly what that portion of code is supposed to be doing.

I’ve really found that the key to learning RSpec is really to get in there and start testing small chunks of code as you write them. Below are some resources that really helped me as I was just starting out.

Resources

  • RSpec actually has super great documentation. A lot of the questions you have can basically be answered there.
  • Better Specs has a lot of really great tips on best practices when it comes to RSpec.
  • If you’re more of a book learner, Effective Testing with RSpec3 has a really good theoretical overview of RSpec. (If you’re looking for specific applications and projects to create while learning, this book may not be for you.)
  • Tutorials Point has a good run through of RSpec if you’re just starting out.

Do you guys have any good RSpec resources? Do you write tests when you code?


Tags: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *