The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Nice new edge feature: test/do declaration style testing

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jonathan Weiss

Posts: 146
Nickname: jweiss
Registered: Jan, 2006

Jonathan Weiss is a Ruby and BSD enthusiast
Nice new edge feature: test/do declaration style testing Posted: Jun 13, 2008 1:58 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jonathan Weiss.
Original Post: Nice new edge feature: test/do declaration style testing
Feed Title: BlogFish
Feed URL: http://blog.innerewut.de/feed/atom.xml
Feed Description: Weblog by Jonathan Weiss about Unix, BSD, security, Programming in Ruby, Ruby on Rails and Agile Development.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jonathan Weiss
Latest Posts From BlogFish

Advertisement

Rails 2 introduced ActiveSupport::TestCase and friends, RoR's enhancement of Test::Unit.

Those extra classes made testing Rails controllers easier and removed the need for cluttered setup methods. Today DHH committed a new feature to ActiveSupport::TestCase (by Jay Fields) that allows Rails tests to match up with RSpec's and Shoulda's nicer declaration style test naming: test/do declaration style testing.

In plain Test::Unit each test would be a method named 'test_' followed by the name the test:

def test_email_format_is_validated
  ...
end

def test_invalid_credit_card_number_throws_exception
  ...
end

This works ok but is a bit clumsy and gets ugly with long method names. In edge you can now write the test like this

test 'email format is validated' do
  ...
end

test 'invalid credit card number throws exception' do
  ...
end

What happens in the background is that ActiveSupport::TestCase will just generate the test_email_format_is_validated method for you. What is missing is a nice integration with the test runner.

This brings Rails developers that envy RSpec's and Shoulda's declarative style to the same level. RSpec&co can still do more tricks but most developers I know really just lust for the it 'should do as I want it to' do ... end syntax and don't really care about the a.should == b.

Read: Nice new edge feature: test/do declaration style testing

Topic: Rails 2 Peepcode Updated w/ 2.1 Features Previous Topic   Next Topic Topic: Developer Testing and the Importance of Context

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use