Getting Wet With REST And Rspec (BDD) November 6th, 2007
REST and BDD are hot topics in software development. So I want to get wet with these topics. So I learned and surveyed from the internet. Okay, I think I get it. To make it practical, I try to apply these topics to Rails. The newest version of Rails (1.2.5) has support for REST. As for BBD, you have to install Rspec Rails gem.
I decided to make a simple clone of my theatre website. I develop front end only. There is no admin interfacte. I just want to learn about REST and BDD not to develop functional website. But maybe later I will add the admin interface.
About BDD…. I think I prefer this one rather than TDD (Rails testing conventional style). I don’t know why. It just seems natural for me. With Rspec (Rails BDD) you get many words ‘should’. You should do that. You should do this. You should not get that. And should bla bla bla. TDD use ‘test’ word. Rspec (BDD) use ‘spec’ word. I have spec my spec files one by one. It’s all okay. But when you spec all automatically by doing ‘rake spec’ command, you get weird errors. Something about ‘SystemStackError: stack level too deep: SET FOREIGN_KEY_CHECKS = 0’. Yeah, I have to do small hack (SET FOREIGN_KEY_CHECKS) because Rails fixtures does not honor my foreign keys. Maybe in Rails, you should not use foreign keys. At least not in development cycle.
About REST…. Yeah, seeing all things as resources is a quite big change paradigm for me. In this theatre website example, you can make four resources. Cities, theatres, movies, and movies schedules. The URL of web application will be quite different than Rails default. You can get resource in many format. Not just html only. You can render it in xml. I still have to learn a lot about this. This e-book helps me a lot.
So here is the web application, built for learning REST and BDD. A simple clone of Cineplex. Download here.
Ehm, I am sure yet. But because of foreign key culprit, I have to add mysql specific hack into test helper file. It just disable and enable foreign keys checks temporary when accessing database with fixtures. So make sure you use Mysql database if you want to try this web application. After loading database fixtures and editing database configuration, you can just run the server. Go to this url: http://localhost:3000/cities/1/theatres
Akbar