Testing Generators

View: New views
4 Messages — Rating Filter:   Alert me  

Testing Generators

by James Byrne-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have started writing my own generators, and I was wondering if anyone
had any suggestions for testing them.

I know I could just run the generator in a dummy application; write my
tests; and then copy the tests back into the generator. But that seems
backwards.

Any ideas?

Thanks
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Testing Generators

by Scott Taylor-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Oct 7, 2008, at 6:02 AM, Pau Cor wrote:

> Hi,
>
> I have started writing my own generators, and I was wondering if  
> anyone
> had any suggestions for testing them.
>
> I know I could just run the generator in a dummy application; write my
> tests; and then copy the tests back into the generator. But that seems
> backwards.
>
> Any ideas?

Why don't you generate the specs when you generate the code?  Then,  
after you've generated the code you tell if the specs are actually  
working...

Scott

_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Testing Generators

by James Byrne-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Scott Taylor wrote:
> Why don't you generate the specs when you generate the code?

That's what I thought I'd have to do. The reason I'm reluctant to do it
is that either I need to write the real code first (and not tests
first). Or I need to rerun my generator every time I write a new test
(or write the code to make the test pass).

It seems awkward, but I guess it isn't avoidable.

Thanks!

--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Testing Generators

by David Chelimsky-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Oct 7, 2008 at 5:24 PM, Pau Cor <lists@...> wrote:
> Scott Taylor wrote:
>> Why don't you generate the specs when you generate the code?
>
> That's what I thought I'd have to do. The reason I'm reluctant to do it
> is that either I need to write the real code first (and not tests
> first). Or I need to rerun my generator every time I write a new test
> (or write the code to make the test pass).

If you know what code you're trying to generate, you could use the
"gold master" approach, where you write a file with the code you want
to produce (the "gold master") and use that as the source of expected
values created by the generator. Using regular expressions or tools
like Hpricot you can do this incrementally.

It's not necessarily easy :) But it does let you write tests first.

Cheers,
David

>
> It seems awkward, but I guess it isn't avoidable.
>
> Thanks!
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users
LightInTheBox - Buy quality products at wholesale price!