Narf: A Ruby Micro Test Framework

I’m a happy user of RSpec, Cucumber and sometimes Steak. Great tools to write specs and features and prove my application does what it’s supposed to do. But sometimes I have the need for something more light weight. ~ For example, sometimes I need to write a single ruby method. Just something ‘quick’ to import a file, convert some data or whatever. Being a good citizen I want to test that method.

RSpec'ing with Time.now

I’m currently writing some RSpec tests that use Time.now. I want my model to calculate a duration and store the future time in the database. I’ve already specced the calculation of the duration, but I also want to spec that everything gets saved correctly. Here’s my first spec: it "should do stuff" do m = Model.create() m.expires_at.should eql(Time.now + some_value) end This fails. It fails because Time.now is quite accurate and some milliseconds have passed between the two calls.