background preloader

Testing

Facebook Twitter

Programming

Integrity | The easy and fun automated continuous integration server. Make sure your system meet these prerequisites: Ruby >= 1.8.6 (currently doesn’t work on 1.9.X) RubyGems >= 1.3.5 git >= 1.6 Then grab Integrity via git, install its dependencies and create the database: $ gem install bundler $ git clone $ cd integrity $ git checkout -b deploy v22 $ bundle install $ bundle lock $ rake db To give it a quick try before going any further, run bundle exec rackup and navigate to $ git fetch origin $ git merge origin/v22 Integrity is configured via the init.rb file using Ruby. Integrity.configure do |c| c.database "sqlite3:integrity.db" c.directory "builds" c.base_url " c.log "integrity.log" c.builder :threaded, 5 c.build_all! Basic settings database Any valid database URI supported by DataMapper. sqlite3:integrity.db directory This is where your projects' code will be checked out.

Base_url log. Shoulda Looked At It Sooner. Just a little bit ago I twittered: I’ve been using shoulda with rspec for past week. Now trying it on fresh rails project and liking it ok thus far. To which Brandon Keepers replied with: @jnunemaker what do you like about it? I started to send a tweet back and realized it would make an ok post here. History I remember asking Brandon at RailsConf last year why he liked RSpec so much (I was using test/spec at the time) and his answer was, “I don’t know, just because.” Of course after that response, he laughed and tried to explain.

Shoulda with RSpec When Joe Ferris announced that shoulda macros could now be used with RSpec, I switched away from rspec-on-rails-matchers pretty quickly. Toe Dipping What is funny, is that I was completely anti-shoulda until they announced RSpec compatibility. The dipping of the toe method reminds me of git-svn. At first, as usual with new things, I was frustrated, followed by excited, followed by frustrated. My Two Favorite Shoulda Things 1. 2. Simple Model Test. Inder Development | Software Developers | Blogs | Real Testing Example, Part Two.

What with upward of two people saying nice things about last week’s post, I’ve decided to keep going with part two of a look at some real testing code. Most code-heavy tutorials show the code but not the tests — I’m doing the opposite here, and showing the tests, but not much of the code. Also, although I’m presenting these tests in chunks, you should realize that there was a lot of back-and-forth from Cucumber to tests to code and some backtracking, most of which I’ll spare you from having to wade through. At the end of last week, I had run through the tests for spam-prevention code which worked by limiting the rate at which a user could send messages to other users of a particular social networking site. Cucumber was involved, and I think I went off on a tangent about writing lots of tests. Once the basic rate limiting code was in place, the client and I came up with a couple of special cases. The application allows a user to explicitly reply to a specific message sent to them.

Inder Development | Software Developers | Blogs | A Real Testing Example. As sort-of promised in last week’s post, I’m going to work through a real-world test example, with an eye toward explaining how and why I tested the way I did. Hopefully, I’ll be able to do this at blog-post length. If not, well, there’s always next week. This site, which was a legacy rescue, allows users to send messages to each other within the site without having to give away their other contact information. The problem is that nefarious spammer types were creating logins and immediately sending messages to large numbers of the user population, irritating them. I started with Cucumber tests — the first two are representative of the initial batch. Background: Given the user database is cleared Given a group of recipients. This test uses an implicit style, so a lot of the details are in the step definitions. Here’s what the steps look like — the user who is not a new member defers to the boilerplate RESTful Authentication step for logging in: Next up, sending messages.

Agile Ajax » Rails Testing Frequently Asked Questions — The Non-Code Version » Pathfinder Development. Between my sessions at RailsConf, and the book promotion at Ruby Learning I’ve been fielding a lot of questions about Test-Driven Development and Rails. Here are five of the most common general questions. Self promotional note: many of these questions and more are covered in detail in Rails Test Prescriptions, only $9 dollars for a book that covers all kinds of testing topics… What test tools should I use? Should I use RSpec? This is, I think, an increasingly common question as the number of available Rails testing tools increases. Most of these tools were created to fill specific needs that were unserved by the Test::Unit and fixture tools provided as the default by Rails.

The important thing is not to get hung up on finding the absolute best test stack before you start — for one thing, you won’t know which tools are best for you until you get going. At that point, if you start hitting the limitations of fixtures, you can move to FactoryGirl or Machinist. Do start using TDD on new code.