Updated jasmine-underscore

March 14th 2012

Last year jasmine-underscore was released. Since then, some issues have been fixed, and two new matchers have also been included:

allToSatisfy
expect([2, 4, 6]).allToSatisfy(function (val) { return val%2 == 0; });
expect([1, 4, 6]).not.allToSatisfy(function (val) { return val%2 == 0; });
anyToSatisfy
expect([2, 3, 5]).anyToSatisfy(function (val) { return val%2 == 0; });
expect([1, 3, 5]).not.anyToSatisfy(function (val) { return val%2 == 0; });

These matchers allow any predicate to be applied to element of a collection, with the test only passing if all/any of the elements in collection satisfy the predicate.

Get version 1.1 here. Enjoy!

Introducing mailcrate

March 12th 2012

Often when I’m working near the top of the test automation pyramid, I find myself needing to test interactions with outside services such as SMTP servers.

On projects in the past, I’ve been able to leverage java tools such as greenmail, which lets me have logic like this.

public class MailerTest {

  private Greenmail greenmail

  @Before
  public void startGreenmail() {
    greenMail = new GreenMail();
    greenMail.start();
  }

  @After
  public void stopGreenmail() {
    greenMail.stop();
  }

  @Test
  public void testYourSendingCode() throws Exception {    
    new Mailer().send("to@localhost.com", "body");

    assertEquals("body", GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]));
  }

}

This library is particularly useful as it allows interrogation of sent mails directly from the test. However, I have had trouble finding an equivalent gem for ruby development. However, there is the fantastic command line tool, mailtrap. Mailtrap is written in ruby and:

Mailtrap waits on your chosen port for a client to connect and talks just enough SMTP protocol for ActionMailer to successfully deliver its message.

Unfortunately, mailtrap does not play nicely with automated tests. It writes out captured emails to the filesystem, and there is no easy way to start, stop or interrogate a server in memory. However, mailtrap and greenmail have acted as the inspiration for mailcrate. Mailcrate is designed to be run from your test code and allows interrogation of sent mails from the test itself. For example:

require 'mailcrate'

describe Mailer do

  before do
    @mailcrate = Mailcrate.new(2525)
    @mailcrate.start
  end

  after do
    @mailcrate.stop
  end

  it 'should use Mailcrate to send mails' do
    mail = Mailer.welcome_email('a@b.com')
    mail.deliver

    @mailcrate.mails[0][:from].should == 'from@example.com'
    @mailcrate.mails[0][:to_list].should include 'a@b.com'
    @mailcrate.mails[0][:body].should include 'Full of awesomeness.'
  end

end

Mailcrate has been published as a gem and can be used by running:

gem install mailcrate

Mailcrate is still rather immature. Any feedback would be welcomed, both here on this blog or its github page.

tags: ruby, mailcrate

Random Excellence - Kevin O'Mara

January 20th 2012

I came across Kevin’s work on a small social networking site. I found myself enjoying a great deal, because his work always stands out for it’s creative composition and attention to detail. His work does not employ heavy post processing, nor does it rely on gimmicky filters or techniques. It stands out for itself, and as a result I keep coming back to it.

Getting ready The Torments of Owlman I feel kind of bad Game not available in all locations Limeade may be the perfect drink Civil Stupidest painting ever Forgotten 1/4 Matthew Gear When I first looked up, I thought it was floating There is a problem with my chair Pal's

subscribe subscribe to this blog

Welcome. Here you'll find Adam Scott's blog and photos. Adam is an agile software developer by trade and a photographer by night.

stuff

popular tags