background preloader

RSpec

Facebook Twitter

RSpec Documentation. (My) RSpec best practices and tips. After a year using RSpec, I’m happy to share “(My) RSpec Best Practices and Tips”.

(My) RSpec best practices and tips

Let’s make your specs easier to maintain, less verbose, more structured and covering more cases! Use shortcuts specify {}, it {} and subject {} You think RSpec is verbose? In case your code doesn’t need any description, use a specify block! Bogdan Gusiev's blog. After a first thousand of tests using Rspec I fount it very annoying to repeat my self testing the standard code as spec code is usually twice longer than code it test.

Bogdan Gusiev's blog

I've started to look for a way to simplify the patterns and make it reusable. Among other nice rspec tricks there is possibility to write custom Rspec matchers. Spec the validation is just two lines of code for each attribute now.