The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
xmp redux: expanding test assertions for profit

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
Eigen Class

Posts: 358
Nickname: eigenclass
Registered: Oct, 2005

Eigenclass is a hardcore Ruby blog.
xmp redux: expanding test assertions for profit Posted: Nov 23, 2005 5:49 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eigen Class.
Original Post: xmp redux: expanding test assertions for profit
Feed Title: Eigenclass
Feed URL: http://feeds.feedburner.com/eigenclass
Feed Description: Ruby stuff --- trying to stay away from triviality.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eigen Class
Latest Posts From Eigenclass

Advertisement

_why just blogged about my xmp code annotator for Ruby and shot the following idea

You know what would be wild? To use this as a way of writing test cases. You write the code that needs to be tested and annotate it with the asserts.

So here is a rough implementation... the enhanced^3 xmp filter will now turn

 require 'test/unit'
 class Foo
   class StillTooSmallWheresYourManhoodDude < Exception; end
   attr_reader :b
   def initialize; @a = [] end
   def foo(x); @a << x end
   def bar; @a.join(" ") end
   def baz; @a.size end
   def foobar; raise StillTooSmallWheresYourManhoodDude unless @a.size > 6; "OK" end
 end

 class TestFoo < Test::Unit::TestCase
   def setup; @f = Foo.new end
   def test_basic_foo
     @f.foo 1
     @f.bar # =>
     @f.baz # =>
     @f.b # =>
   end

   def test_more_foo
     @f.foobar # =>
     10.times{|i| @f.foo i }
     @f.bar # =>
     @f.foobar # =>
   end
 end

into

 require 'test/unit'
 class Foo
   class StillTooSmallWheresYourManhoodDude < Exception; end
   attr_reader :b
   def initialize; @a = [] end
   def foo(x); @a << x end
   def bar; @a.join(" ") end
   def baz; @a.size end
   def foobar; raise StillTooSmallWheresYourManhoodDude unless @a.size > 6; "OK" end
 end

 class TestFoo < Test::Unit::TestCase
   def setup; @f = Foo.new end
   def test_basic_foo
     @f.foo 1
     assert_equal("1", @f.bar)
     assert_equal(1, @f.baz)
     assert_nil(@f.b)
   end

   def test_more_foo
     assert_raise(Foo::StillTooSmallWheresYourManhoodDude){@f.foobar}
     10.times{|i| @f.foo i }
     assert_equal("0 1 2 3 4 5 6 7 8 9", @f.bar)
     assert_equal("OK", @f.foobar)
   end
 end
 # >> "Loaded suite -\nStarted\n..\nFinished in 0.000819 seconds.\n\n2 tests, 0 assertions, 0 failures, 0 errors\n"

Read more...

Read: xmp redux: expanding test assertions for profit

Topic: Hoodwink.d? Previous Topic   Next Topic Topic: My Repository Transplant

Sponsored Links



Google
  Web Artima.com   

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