0

John Lams ironRuby unit-testing framework

by klh 9. juli 2008 08:03

I read an excellent post by John Lam, about his talk at TechEd 2008 on IronRuby

In the post he has screen shots of some ironRuby code for at simple unit-testing framework.

I tried looking around to find the code, but could not find it anywhere.

Hence I decided to type it in myself (reminds me of the days when you would get a hold of a C64 magazine and type in some example and three hours later see a baloon flying around your screen ...)

Anyway this is not code I made, this is John Lams work:

 

$examples = 0
$messages = []

class PositiveExpectation
  def initialize(obj)
    @obj = obj
  end
  def ==(other)
    $examples += 1
    if @obj != other
      $messages << "Want #{@obj.inspect} got #{other.inspect}"
      print "E"
    else
      print "OK"
    end
    end
end

class Object
  def should
    PositiveExpectation.new(self)
  end
end

def it(description)
  print "\n it #{description}: "
  yield
end

def describe(description)
  print "#{description}"
  yield
  puts "\nend\n"
end

at_exit do
  puts "#{$messages.length} / #{$examples} failed"
  if $messages.length > 0
    puts "Failures: "
    $messages.each { |m| puts "- #{m}"}
  end
end

Tags:

0

About ruby

by klh 27. april 2008 03:23

Since there has been so much hype about ruby, I thought I'd better take a look at it.

I must say it looks really good. There's two things i like about Ruby:

1. Duck-typing

So many times I have been trying to make generic functionality for classes I didn't own. So in C# I have no chance of implementing a common interface.

With Duck-typing that is now possible, since I find that common functionality and do Duck-typing.

2. SOAP communication

WOAW, that was sure easy, I implemented a small serice in WCF and tried consuming it in Ruby - 20 secs. and it was done.

require 'soap/wsdlDriver'
require 'cgi'

WSDL_URL = http://localhost:8000/?wsdl
soap_client = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver

# Log SOAP request and response
soap_client.wiredump_file_base = "soap-log.txt"

# Call reset method.
result = soap_client.Test("klaus")
puts result.inspect

# Call stopGenerate method.
#result = soap_client.stopGenerate('1')
puts result.inspect

Powered by BlogEngine.NET 1.4.5.0
Original Design by Laptop Geek, Adapted by onesoft