Sitemap
Cory Diamand

Cory Diamand

Product guy, Ruby on Rails dev

RSpec and the power of a puzzle

How fixing scaffold generated RSpec tests can be a powerful exercise for the novice Rails dev.

2 min readApr 19, 2014

--

The Power of a Puzzle

I am a junior Rails developer. When I started learning to program I did a lot of programming puzzles to help me build my chops. Puzzles are an effective learning tool because you feel excitement in trying to solve them, and you get this amazing satisfying feeling upon completion. I find that I generally learn more by working on a puzzle than by following an example in a book or off a blog.

The Red Challenge

I’ve started writing basic RSpec tests for the apps I’m building.

I’ve found that as I go back and work through the tests that have been generated for me by scaffolding, what I’ve really been presented with are many small puzzles.

Get Cory Diamand’s stories in your inbox

Join Medium for free to get updates from this writer.

Some are pre-generated and require input to work:

What the eff do I put in here?

Other times you need to update the test to match how your app works:

Press enter or click to view image in full size
Does my app even redirect here anymore?

Thanks to RSpec’s red and green fail/pass system, I feel a nice mix of motivation and satisfaction while working on each test. As a kid who grew up playing videogames, this kind of feedback really works for me:

Press enter or click to view image in full size
Still have some work to do….

The Green Satisfaction

So if you’re new to Rails, or just hesitant about testing, I recommend you give this a try. Let Rails do the work and generate your first set of tests for you, and then just try to fix them. I think you’ll find you’re learning alot and having fun at the same time.

--

--

Cory Diamand
Cory Diamand

Written by Cory Diamand

Product guy, Ruby on Rails dev