sameera207
sameera207

Reputation: 16629

listing the names and the attributes of factories (FactoryGirl)

I want to write a ruby script to list the names and their attributes of factories in a project (with factory girl). My problem is, I'm not sure how can I determine the start and end of a given factory

The approach I'm thinking is to,

But the downside of this is, If the alignments are different I will not be able to determine the end point of the factory.

My questions are,

I checked rubocop, and their approach to handle alignments, but seems like since its a general approach, its complicated. I believe their should be an easier way.

Upvotes: 1

Views: 592

Answers (2)

Joe Ferris
Joe Ferris

Reputation: 2732

If you need to actually parse the factories.rb file and can't just execute the Ruby, I'd strongly recommend using a true parser like Ripper instead of writing a string parser for Ruby yourself.

Upvotes: 1

John Feminella
John Feminella

Reputation: 311605

That seems like quite a bit of overkill. You can just ask FactoryGirl itself, since each Factory has an attributes object and name associated with it.

Upvotes: 1

Related Questions