alexrothenberg / ammeter

A gem that allows for you to write specs for your Rails 3 generators
MIT License
89 stars 28 forks source link

Passing options to a generator #41

Open derekprior opened 10 years ago

derekprior commented 10 years ago

I have a generator that inherits from NamedBase and defines a --sql class_option.

I invoke it with run_generator["foo", "--sql bar"] but inside the generator options[:bar] is nil. I looked at the implementation of run_generator and generator and saw that it's using Thor to parse the options. I verified that Thor::Options.splt works as expected on the array I'm passing to run_generator... and yet, still the option in nil in the generatornd it seems that indeed args and opts are getting set correctly. And yet, the option is still nil in my tests.

Compounding the problem (and limiting my normal debug tools) is that it seems pry does not work inside the generator. It works in my non-generator spec and even works when I run the generator from the command line, outside of my tests. But in my generator specs, pry opens but no statements return anything. I can call methods, non-existent methods, pry method -- none of them do anything.

The generator runs as expected when I try it from the command line so the problem is indeed limited to the specs.

d4rky-pl commented 10 years ago

I invoke it with run_generator["foo", "--sql bar"] but inside the generator options[:bar] is nil

Shouldn't that be options[:sql] ?

derekprior commented 10 years ago

Yes. That was a typo in the issue. Still seems to be a problem.

On Wednesday, August 13, 2014, Michał Matyas notifications@github.com wrote:

I invoke it with run_generator["foo", "--sql bar"] but inside the generator options[:bar] is nil

Shouldn't that be options[:sql] ?

— Reply to this email directly or view it on GitHub https://github.com/alexrothenberg/ammeter/issues/41#issuecomment-52022701 .

alexrothenberg commented 10 years ago

I believe it works if you separate the name and value like

run_generator["foo", "--sql", "bar"]