[Ironruby-core] RSpec Test Format

Kevin Radcliffe lists at ruby-forum.com
Tue Jul 7 14:44:27 EDT 2009


Mohammad Azam wrote:
> I have done BDD in C# and my question is that how Spec in IronRuby makes
> it easier. Here is what my test looks like:

> <snip test code....>

> Is this the normal way of writing unit test BDD style using Spec and
> IronRuby or am I missing something?

I'm definitely no BDD expert, but I'll try to take a stab at it.
Apologies if I put my foot in my mouth.
People actually using BDD full-time, please chime in and/or shoot me 
down.

Personally, I believe that some of this is just aesthetics, and some of 
it is actually aiming to make you think about making your libraries' 
intent as clear as possible.
I think you can refactor as you go, and when the specifications read 
close to natural language, you've gotten somewhere.

Re: Your specific question about what RSpec brings that C# can't 
achieve..
I think it's the same as most ruby vs. C# issues, ruby gets out of our 
way, where C# simply isn't able to.

I'd say the closest you get (arguably) in C# is MSpec:

http://codebetter.com/blogs/aaron.jensen/archive/2008/05/08/introducing-machine-specifications-or-mspec-for-short.aspx
http://github.com/machine/machine.specifications/tree/master

Where you have to work around what the C# compiler needs, you have to 
write things like:

Because of = () =>
      fromAccount.Transfer(1m, toAccount);

Check here for a simple MSpec example:
http://github.com/machine/machine.specifications/blob/0db4d72c93fdc4f5775d9b1eb6239b64a76ad562/Source/Machine.Specifications.Example/BankingSpecs.cs

I'm not trying to knock MSpec at all, but if you look at what you've 
written above to achieve the same context/specification style, I think 
you might agree ruby does a better job getting out of your way to let 
you do what you intend.

The C# compiler needs a lot more to be happy, so MSpec does its very 
best to get around that.

There is a lot of good material around RSpec and Cucumber, and the art 
of writing specifications for it as well.
-- 
Posted via http://www.ruby-forum.com/.


More information about the Ironruby-core mailing list