My journey into testing (An RSpec-2 Factory Girl and Guard Tale)
Testing has always been to me this thing of, “if i had more time”, or “if the project had money to cover testing.”, but I have begun to realize that testing can be development as it not only helps guide good programming it makes it much simpler to keep your code in tip top shape.
As this is part 1, I wanted to talk about setting up testing environments. This is something that I feel like isn’t talked much about on the web, yet it is something almost all people expect when working on open source projects, “Could you add some tests to your code?”.
gem 'rails', '3.1.3' ... gem "rspec-rails", ">= 2.0.1", :group => [:development, :test] gem 'guard-spork', :group => [:development, :test] gem "factory_girl_rails", :group => [:development, :test] group :development do gem 'spork', '~> 0.9.0.rc9' #Greatly Speeds up Automated Testing gem 'guard' #the magic of automated testing gem 'guard-bundler' gem 'guard-rspec' gem 'growl' gem "progress_bar" gem 'ruby-debug19' end
rspec is an alternative testing framework, read more about it here
RSpec is a Behaviour-Driven Development tool for Ruby programmers. BDD is an approach to software development that combines Test-Driven Development, Domain Driven Design, and Acceptance Test-Driven Planning. RSpec helps you do the TDD part of that equation, focusing on the documentation and design aspects of TDD.
I am still learning the fundamentals of RSpec so I will follow up on this
Guard has worked out to be my controller of my testing environment. It’s primary role is to simply watch for changes and perform action when a change in my code is detected, typically through a filesystem event such as saving a file. It has an impressive list of “guards” that can be found on it’s wiki, and I will talk about a few I am using but you really should check this out. Coupled with growl it is an amazing tool.
Spork and Guard-spork
Spork is a time saver, Plain and simple. It launches your rails environment in a separate process that it can fork as you go through your testing. Basically it prevents you from loading the entire environment on ever test run, as our goal here is an auto test environment were tests will be run constantly the quicker the feedback on the code the better.
Automatically runs bundle install when a change in your gemfile is detected (Awesome)
This is the icing on the cake of Guard growl notifications of all the guard output to keep your focus on the code. Without removing focus you get your testing status.