DAZ is the author of Jump Start Sinatra, a short book that helps you to get up to speed with Sinatra over a weekend. He's been using Sinatra since 2009. DAZ lives in Manchester, UK where he teaches maths and plays water polo.
Writing tests for your app is kind of like ensuring that your car brakes will still work, even if you accidentally change the language of your sat-nav to German. Really, it’s about avoiding nasty surprises. Today, I’m going to show you how to write tests in Ruby using MiniTest. Enjoy!
Sinatra is often used to develop small applications and APIs, but it can easily cope with complex modular applications with large amounts of end points. I’ve chosen the names of the three different styles of application structure based on the size of the application:
- SMALL – all the code in a single file
- MEDIUM – tests in a separate file and a separate views folder
- LARGE – a modular-style application
To demonstrate each of these three different structures, I’m going to build an application, using exactly the same underlying code in each of the three styles.
Ask anybody to name a Ruby frameworks and most people will answer ‘Ruby on Rails’. If you ask for a smaller framework, they’ll probably answer ‘Sinatra’ (which technically isn’t a framework it’s a Domain Specific Language, but let’s not get too technical). Rails and Sinatra are the darlings of the Ruby web development world. Together, they seem to have all the bases covered, which I concluded in this post. Given the success of these two ‘frameworks’, is there a need for any others?
Well, it turns out that there are actually quite a few Ruby microframeworks kicking around (technically, some of these are DSLs too, but the term microframework seems to have stuck). Here are six projects that I found on GitHub:
- Hobbit, created by Patricio Mac Adden
- New York, New York (NYNY), created by Andrei Lisnic
- Brooklyn, created by Luis Lavena
- Scorched, created by Tom Wardrop
- Cuba, created by Michel Martens
- Nancy, created by Guillermo Iguaran
My first reaction was that they seemed to be occupying a very similar space to Sinatra, which I thought had the ‘microframework’ area of Ruby web development covered. I wondered why all these microframeworks exist. What’s the point?
This article was sponsored by New Relic. Thank you for supporting the companies who make SitePoint possible! Analyzing the performance of your web application is important. There may be bottlenecks that are affecting a certain group of users or there might be errors that haven’t been identified in testing. Often, an application won’t react the […]
It’s that time of year again when the Ruby community vote for their heroes. The Ruby Hero awards are now entering their 7th year and have become an awesome tradition of recognising and celebrating the contributions of those Rubyists who give something back.
This entry is part 6 of 6 in the series Getting Started with RubyWelcome to the last post in the Getting Started with Ruby series. In the previous post, we covered writing our own methods. In this post, we’ll learn all about how classes work: How to create them, how to create methods for them, […]
This post was inspired by this brilliant video, where Konstantin Haase, the maintainer of Sinatra builds a fully working app and deploys it on Heroku with tests on Travis (where he works). I decided to do a similar example that walks through each step of building an API service that demonstrates a typical Sinatra development […]
This entry is part 5 of 6 in the series Getting Started with RubyWe’ve covered some of Ruby’s most important object types in the last three posts – Strings, Integers & Floats and collections such as Arrays, Ranges and Hashes. We’ve also looked at the methods that give these objects their functionality. In this post, […]
This entry is part 4 of 6 in the series Getting Started with RubyIn the last post we covered numbers and their methods. In this post we’re going to look at some of Ruby’s collections such as Arrays, Hashes and Ranges. We’ll look at what they are, what they’re used for, and what they can […]
This entry is part 3 of 6 in the series Getting Started with RubyThe last part of this series looked at strings and their methods, along with storing information as variables. We also wrote a Greeter program and Madlibs program, making web versions of them both using Sinatra. In this post, the focus is how […]