technicalpickles

Open Source ProjectsCode that Might be Useful to You

Talks I've GivenOn Technologies and Ideas

ThoughtsWhere I Sometimes Write Things

Resume If You Believe In Those

Follow Me On

GitHubIf coding is your thing

TwitterIf you tweet

Shoulda and assert{2.0} make swell bedfellows


I have been generally using RSpec for my testing needs, but I’ve recently been persuaded to use Shoulda on a few projects.

For most things, they seem about on par.

One thing I missed in particular was the ‘should’ syntax of RSpec, like:

x.should == 42

As opposed to using test-unit’s:

assertEqual 42, x

I haven’t been able to entirely quantify why I prefer the former syntax, but I think it has to do with more succinctly expressing the assertion.

While I haven’t found quite to replace that style syntax, I do have something that fits my craving: assert {2.0}. This gives us something like:

assert {x == 42}

I think I’m actually digging this over the other two styles, because:

  • If you can come up with an expression, you can assert it.
  • Nice output when the assertion fails.
comments powered by Disqus