Twitter GitHub Facebook Instagram

Daniel Irvine on building software

RSpec expectations in loops

22 May 2014

In my last past, From C# to Ruby: Test assertions in loops, I mentioned that the following code is an RSpec antipattern:

But what about this?

describe your context do

  TRUTHS.each |t| do
    it returns true when running func_under_test with  + t.to_s
      func_under_test?(t).should eq true

This form is much better, because the correct number of expectations will be returned and easily understandable error messages will be returned in case of failure.

About the author

Daniel Irvine is a software craftsman at 8th Light, based in London. These days he prefers to code in Clojure and Ruby, despite having been a C++ and C# developer for the majority of his career.

For a longer bio please see To contact Daniel, send a tweet to @d_ir or use the comments section below.

Twitter GitHub Facebook Instagram