Starting to dig through the tests
One thing that has always amazed me about Ruby is how much you can get done with so little code. I was talking at lunch with our architect about the Ruby language tests (in %YourIronRubyFolder%\Tests\Ruby\Builtin) and I asked “Think they ported over test::unit first?”. Boy was I wrong.
I’ve only dug through a couple tests, but their elegance is already quite apparent, and they got there very simply. Here is an example test
-
-
describe “Array#new“ do
-
it “creates an empty array via language syntactical sugar“ do
-
a = []
-
a.length.should == 0
-
end
It reads very well, and then the output to the screen looks like this.
Array#new
it creates an empty array via language syntactical sugar: .
The IronRuby team achieved this feat with a very small amount of code in simple_test.rb (\Tests\Ruby\Util\simple_test.rb). They simply added a few methods to object that output the string to the screen, and yield the block for execution. Below are Describe, it and should, although there is more in simple_test.rb that I would encourage you to look at.
-
-
class Object
-
def describe(message)
-
puts “nn#{message}“
-
yield
-
end
-
-
def it(name)
-
print “n it #{name}: “
-
$name = name
-
yield
-
end
-
-
def should
-
PositiveExpectation.new(self)
-
end
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
July 26th, 2007 at 3:57 am
Looks rather like rspec, possibly a stripped-down subset thereof.
http://rspec.rubyforge.org/
Doesn’t make it a bad thing, mind.
July 26th, 2007 at 5:04 am
Not at all.. The little I’ve seen of rspec has been impressive. Of course we’re all wondering what it will take to bring packages like rspec over, but not sure it’s time to ask that yet
July 26th, 2007 at 7:08 am
Please let me point out that the IronRuby specs are based on the ones from Rubinius.
Rubinius has mini-spec which allows it to use rspec-notation without actually being able to run RSpec.
Those specs are designed to be useful for *all* Ruby implementations.