small medium large xlarge

30 Aug 2013, 10:47
Robert Dober (20 posts)

Sinatra Part: Test (Specs)

It is surprising that you include tests in this work. OTOH that is really great because it shows how much testing is considered automatic nowadays. OTOH testing is a tricky business.

You have chosen RSpec as a framework and that is a mainline choice. So much mainline that I am afraid it is almost a must to follow certain conventions. These conventions are, at least:

  • One spec directory per app/lib.

  • One spec_helper.rb file per spec to assure maximum consistency for loaded libs, environment and RSpec setup.

  • Naming -test- sorry I meant specs *_spec.rb

Now, again, I am fully aware that this book is neither about testing or RSpec, however, I feel that it is benificial for your readers to get the first impression accordingly to established best practtices.

But the biggest problem your tests are having is the access to the development database, which implies two major inconveniences:

  • Tests will interfere with the application.

  • Tools like Database Cleaner ( cannot be used anymore.

And validations for uniquness at latest will make the usage of such tools completely necessary.

I suggest to adapt the code to this environment awareness and introduce the standard RSpec layout and naming conventions. This does not necessarily need to bloat the text of the book, I guess external links or even additions to the TODOs might be able to cover this issue.

After talking so much I have taken the time to create two gists with tested code that would be a solid setup for a DataMapper using Sinatra project.

Here are the refs:



03 Sep 2013, 07:39
Robert Dober (20 posts)

As a newbie to Sinatra I did a lousy job for setting the environment, pls kindly refer to the Sinatra docs themselves

Cheers R

04 Sep 2013, 21:28
Fred Daoud (22 posts)

I added a reference to the docs, thanks Robert.

You must be logged in to comment