Skip to main content

Posts

Showing posts from September, 2012

Getting started with Ruby on Rails 3.2 and MiniTest - a Tutorial

For fun, I thought I would start a new Ruby on Rails project and use MiniTest instead of Test::Unit. Why? Well MiniTest is Ruby 1.9s testing framework dejour, and I suspect we will see more and more new projects adopt it. It has a built in mocking framework and RSpec like contextual syntax. You can probably get away with fewer gems in your Gemfile because of that. Getting started is always the hardest part - let's jump in with a new rails project rails new tddforme --skip-test-unit Standard stuff. MiniTest sits nicely next to Test::Unit, so you can leave it in if you prefer. I've left it out just to keep things neat and tidy for now. Now we update the old Gemfile: group :development, :test do gem "minitest" end and of course, bundle it all up.....from the command line: $ bundle Note that if you start experiencing strange errors when we get in to the generators later on, make sure you read about rails not finding a JavaScript runtime . Fire up...

Javascript - Objects by ref

If any language should have been name after a snake, Javascript should have. It's a slippery little thing I tell you. It slithers and slides and wraps around you. And you have to work like a snake charmer to coax it out of its basket and make it play nicely without biting you. Take, for example the simple idea of passing a variable by ref or by val. Javascript's snakey little implementation means that if you are passing a variable then you'll never pass it by ref. However if you are passing an object, then, hey presto, by ref it is. Bear witness: var globalVar; var anObj = function() { this.value = "default value"; } function changeValue(arg){ arg.value = "Changed by function"; } function changeUp(arg) { arg = "Changed"; } globalVar = "global"; console.log(globalVar); changeUp(globalVar); console.log(globalVar); var myObj = new anObj()...

Ruby frameworks, Rails and Padrino

Some thoughts on the Padrino and Rails . For the past few weeks, I've been working on a small project that is using Padrino rather than Rails. The interesting thing was that the decision for the technology was based on the idea that the project was only going to have a few objects; at most five or six and as such, didn't need something as large, complex or weighty as Rails . However, something as barebones as Sinatra would not allow for some of the more rapid application development that you get from some of the baked in goodness of Rails - things like Sessions, Flash, Form helpers and generators all speed up development fairly considerably. With that in mind, Padrino was the framework of choice. Now Padrino is interesting. It's a great little framework, but, the temptation is to look at it's relative light-weightedness in comparison to Rails and think it will require less learning time or up-front knowledge for someone with little experience of the framework or of so...