Posts Tagged ‘stub’

Captchas with rails and multiple servers

Friday, August 17th, 2007 by Alexander Lang
captcha

On autoki.com we have this “Tell-a-friend” functionality, where people can enter the email addresses of their friends and have the link to a cool photo or car sent to them. Until recently this was only accessible to logged in users because we were afraid of spam bots using it to send emails to everyone using our servers. At some point we realized that this function could be much more useful if everyone would be able to use it – member or not. The solution we chose to fight the spam bots was pretty standard: Captchas – Completely Automated Public Turing tests to tell Computers and Humans Apart. (I just love this name)

(more…)

Using Mocha – A review

Wednesday, August 1st, 2007 by Thilo Utke

For aprox. 3 months we have been using mocha now. And we promised to get back to this subject when we passed our 2000th revision.

In this post I’d like to share some expirence we made while using mocha. But first a short introduction to mocha taken from the rubyforge page.

Mocha is a library for mocking and stubbing using a syntax like that of JMock, and SchMock. One of its main advantages is that it allows you to mock and stub methods on real (non-mock) classes and instances.

We started to use mocha on an existing test suite and changed our test code in place when we wrote a new test or had to update old ones. The transition was mostly painless, there were three things where we stumbled.
(more…)

Wir machen unseren Tests Beine

Friday, March 30th, 2007 by Thilo Utke

Da unsere vielen Tests mittlerweile ein wenig lange brauchen, haben wir uns am heutigen Forschungstag mal wieder mit dem Problem Testing auseinandergesetzt. Das Ergebniss diesmal schon vorne weg: unsere erfolgreichste Entdeckung ist Mocha.
Mit diesem Framework lassen sich Stubs und Mocks mit realen Objekten verwenden. Es folgt ein kleiner Auszug aus unserem bisherigen Testcode.

def create_activated_user(attributes = {})
email = generate_email_address
User.create!({:gender => ‘m’, :first_name => ‘joe’, :last_name => ‘doe’, :email => email,
:password => ‘test’, :password_confirmation => ‘test’, :city => “berlin”, :status => ‘active’
}.merge(attributes))
end

def create_auto(user = nil, attributes = {})
user = create_user unless user
Auto.create!(auto_hash(user).merge(attributes))
end

def test_activity_returns35_for_user_with_picture_and_auto_with_picture
user = create_activated_user :photo => ‘1.gif’
create_auto user, :photo => ‘2.gif’
assert_equal(35, user.activity)
end

Dauer: 795ms

Nach kurzem Studium des Mocha Cheat Sheets haben wir dann den Test wie folgt geändert.

def test_activity_return35_for_user_with_picture_and_auto_with_picture
with_photos = stub :with_photos => [Auto.new(:photo =>'test.gif')]
user = User.new :photo => ‘1.gif’
user.stubs(:autos).returns(with_photos)
assert_equal(35, user.activity)
end

Dauer: 49ms

Na wenn das keine signifikate Verbesserung ist. Auf Mocha gestoßen sind wir über den Testing Rails Blog, auf dem leider nichts Neues mehr zu passieren scheint. Eine kleine Übersicht von Stub-Frameworks mit problemspezifischen Einschätzungen fanden wir auf dem Blog von Jay Fields.

Wir werden Mocha in der nächsten Zeit in unseren Test integrieren, und bei der 2000ten Revision sagen wir euch wie lange unsere Test Suite läuft.