Tag Archives: test

Check if selected date is correct with cucumber

The default web steps provided by cucumber provide a way to check the content of a text field : the "..." field should contain "...", but how to check if the date selected by default in a form is correct ?

To describe some of the features of the coming PigeBox web interface, we needed something like : the "..." datetime should contain "17:00:00".

Even if webrat doesn’t provide the builtin method to “read” a Rails datetime select, this piece of code adds the method selected_datetime to webrate scope.

With this small webrat extension, the following step becomes possible :

Continue reading

Install CruiseControl.rb on debian or ubuntu

CruiseControl.rb is a continuous integration tool. It runs a build process when modifications are detected in a project. Java developers know CruiseControl (often discussed in this blog). CruiseControl.rb is very practical for projects built with rake, especially rails projects.

For example, CruiseControl.rb can:

  • follow several branches of your project,
  • run tests or specs in a clean environment,
  • notify our team when something goes wrong (by email, twitter, jabber, irc, campfire, …),
  • deploy with capistrano our development stage when specs are verified,

This CruiseControl.rb debian package is based on CruiseControl.rb github branch of ThoughtWorks.

Continue reading

Test ActionMailer for a multipart mail

When your ActionMailer creates multipart mails with both html et text bodies, your unit test can become a nightmare. The default policy to test ActionMailer (provided by the generated testcase) is comparing the created mail content with a static fixture. It’s very difficult to maintain. And this approach is impossible with a multipart mail. Several things in the encoded mail are randomly created (like the mimepart boundaries).

Another policy is promoted by Dave Thomas in his book Agile Web Development with Rails or Shanti A. Braford. The principle is simple : test only that the important information is present into the mail body.

This approach is meanful in a html/text mail. The two parts contain often the same important information. So the same assertions can be performed on the two parts of the mail :

sent.parts.each do |part|
  assert_match #{user.name}, part.body, "#{part.content_type} invalid"