Generators not listed only install #722

Closed
hron84 opened this Issue Mar 26, 2013 · 14 comments

Comments

Projects
None yet
6 participants
@hron84

hron84 commented Mar 26, 2013

I tried to discover what generators provided by RSpec-Rails but only rspec:install is listed. However, if i run rails g rspec:model i get the correct help text, so generator is available.

The rails g rspec:install ran correctly, without any errors. In config/application.rb I have a following settings:

    config.generators do |gen|
      gen.test_framework :rspec, :fixture => true, :views => false, :view_specs => false
      gen.fixture_replacement :factory_girl, :dir => 'spec/factories'
      gen.stylesheet_engine :scss
      gen.template_engine :haml
    end
@awilfox

This comment has been minimized.

Show comment Hide comment
@awilfox

awilfox Mar 31, 2013

Contributor

This behaviour is noted in the documentation. The list of generators can be found in the lib/generators/rspec directory.

Contributor

awilfox commented Mar 31, 2013

This behaviour is noted in the documentation. The list of generators can be found in the lib/generators/rspec directory.

@hron84

This comment has been minimized.

Show comment Hide comment
@hron84

hron84 Mar 31, 2013

Hmm... well, I understand what motivated this decision. However, they should be listed on the help text of rspec:install . just for information.

hron84 commented Mar 31, 2013

Hmm... well, I understand what motivated this decision. However, they should be listed on the help text of rspec:install . just for information.

@alindeman

This comment has been minimized.

Show comment Hide comment
@alindeman

alindeman Apr 1, 2013

Contributor

Normally the generators are invoked alongside rails generate model, for instance. Do you have a good use case for invoking one outside that flow?

Contributor

alindeman commented Apr 1, 2013

Normally the generators are invoked alongside rails generate model, for instance. Do you have a good use case for invoking one outside that flow?

@hron84

This comment has been minimized.

Show comment Hide comment
@hron84

hron84 Apr 1, 2013

Yeah, if I write a model what is not an ActiveRecord::Base but an ActiveResource model. These models cannot generated via rails generate model.

hron84 commented Apr 1, 2013

Yeah, if I write a model what is not an ActiveRecord::Base but an ActiveResource model. These models cannot generated via rails generate model.

@dchelimsky

This comment has been minimized.

Show comment Hide comment
@dchelimsky

dchelimsky Apr 1, 2013

Member

Even though they are not displayed, you can run rails generate rspec:model and it will only generate the model spec (not the model itself).

Visibility is managed by Rails, not RSpec. Rails offers an API to register generators, but does not expose a means to control which ones are displayed, which Rails manages directly: https://github.com/rails/rails/blob/master/railties/lib/rails/generators.rb#L162-L190.

In order for RSpec to display the other generators, we'd have to monkey patch Rails, which I would strongly recommend against as that was the reason rspec-rails-1.x had so many surprise-post-rails-release-releases (whereas that has happened only once in rspec-rails.2.x).

We could theoretically add documentation to the description in https://github.com/rspec/rspec-rails/blob/master/lib/generators/rspec/install/install_generator.rb#L5-L8 but I wouldn't recommend it because it's not normal usage (as in no other extensions that I am aware of do this) to display information about other generators from one generator. There is no concept of a "master generator."

I can appreciate the desire to discover this information programmatically (vs finding docs), but I think that change needs to happen in Rails, not RSpec.

Member

dchelimsky commented Apr 1, 2013

Even though they are not displayed, you can run rails generate rspec:model and it will only generate the model spec (not the model itself).

Visibility is managed by Rails, not RSpec. Rails offers an API to register generators, but does not expose a means to control which ones are displayed, which Rails manages directly: https://github.com/rails/rails/blob/master/railties/lib/rails/generators.rb#L162-L190.

In order for RSpec to display the other generators, we'd have to monkey patch Rails, which I would strongly recommend against as that was the reason rspec-rails-1.x had so many surprise-post-rails-release-releases (whereas that has happened only once in rspec-rails.2.x).

We could theoretically add documentation to the description in https://github.com/rspec/rspec-rails/blob/master/lib/generators/rspec/install/install_generator.rb#L5-L8 but I wouldn't recommend it because it's not normal usage (as in no other extensions that I am aware of do this) to display information about other generators from one generator. There is no concept of a "master generator."

I can appreciate the desire to discover this information programmatically (vs finding docs), but I think that change needs to happen in Rails, not RSpec.

@hron84

This comment has been minimized.

Show comment Hide comment
@hron84

hron84 Apr 1, 2013

@dchelimsky okay, I got it. And what about providing a list in Generators.md (in wiki) and providing a link to it on rspec:install help page? Just to inform developer there is more than he see.

hron84 commented Apr 1, 2013

@dchelimsky okay, I got it. And what about providing a list in Generators.md (in wiki) and providing a link to it on rspec:install help page? Just to inform developer there is more than he see.

@dchelimsky

This comment has been minimized.

Show comment Hide comment
@dchelimsky

dchelimsky Apr 1, 2013

Member

Docs are at http://rubydoc.info/gems/rspec-rails and https://www.relishapp.com/rspec/rspec-rails/docs, either or both of which would be good targets. I think that's a great solution to the documentation issue to add a pointer from the rspec:install description. Any interest in submitting a PR?

Member

dchelimsky commented Apr 1, 2013

Docs are at http://rubydoc.info/gems/rspec-rails and https://www.relishapp.com/rspec/rspec-rails/docs, either or both of which would be good targets. I think that's a great solution to the documentation issue to add a pointer from the rspec:install description. Any interest in submitting a PR?

@hron84

This comment has been minimized.

Show comment Hide comment
@hron84

hron84 Apr 1, 2013

@dchelimsky problem: nor RDoc nor https://www.relishapp.com/rspec/rspec-rails/v/2-13/docs/generators does not lists available generators, only repeats "no generators listed, only rspec:install" etc. Docs are incomplete in this topic and should not pointed from help text until they are fixed.

hron84 commented Apr 1, 2013

@dchelimsky problem: nor RDoc nor https://www.relishapp.com/rspec/rspec-rails/v/2-13/docs/generators does not lists available generators, only repeats "no generators listed, only rspec:install" etc. Docs are incomplete in this topic and should not pointed from help text until they are fixed.

@dchelimsky

This comment has been minimized.

Show comment Hide comment
@dchelimsky

dchelimsky Apr 2, 2013

Member

Those docs are in git with the project, so they'll get updated when the gem is released. Make sense?

Sent from my iPhone

On Apr 1, 2013, at 6:59 PM, Gabor Garami notifications@github.com wrote:

@dchelimsky problem: nor RDoc nor https://www.relishapp.com/rspec/rspec-rails/v/2-13/docs/generators does not lists available generators. Docs are incomplete and should not pointed from help text until they are fixed.


Reply to this email directly or view it on GitHub.

Member

dchelimsky commented Apr 2, 2013

Those docs are in git with the project, so they'll get updated when the gem is released. Make sense?

Sent from my iPhone

On Apr 1, 2013, at 6:59 PM, Gabor Garami notifications@github.com wrote:

@dchelimsky problem: nor RDoc nor https://www.relishapp.com/rspec/rspec-rails/v/2-13/docs/generators does not lists available generators. Docs are incomplete and should not pointed from help text until they are fixed.


Reply to this email directly or view it on GitHub.

@hron84

This comment has been minimized.

Show comment Hide comment
@hron84

hron84 Apr 2, 2013

Yeah, it makes.

hron84 commented Apr 2, 2013

Yeah, it makes.

@alindeman

This comment has been minimized.

Show comment Hide comment
@alindeman

alindeman Apr 6, 2013

Contributor

@hron84, are you interested in writing some docs?

Contributor

alindeman commented Apr 6, 2013

@hron84, are you interested in writing some docs?

@hron84

This comment has been minimized.

Show comment Hide comment
@hron84

hron84 Apr 6, 2013

I should be interested in it, however I think my English is not enough for it, so I would like to skip it if it is possible. It will be good for everyone.

hron84 commented Apr 6, 2013

I should be interested in it, however I think my English is not enough for it, so I would like to skip it if it is possible. It will be good for everyone.

@fontno

This comment has been minimized.

Show comment Hide comment
@fontno

fontno May 20, 2013

Contributor

since I use rspec-rails everyday. PR on its way.

Contributor

fontno commented May 20, 2013

since I use rspec-rails everyday. PR on its way.

@eliotsykes

This comment has been minimized.

Show comment Hide comment
@eliotsykes

eliotsykes Dec 13, 2014

Contributor

Here's an initializer script that modifies the public Rails::Generators.hidden_namespaces config so the RSpec generators are no longer hidden when listing all available generators by running rails g.

https://github.com/eliotsykes/rspec-rails-examples/pull/11/files

I'll shortly take a go at submitting a pull request with a similar change to rspec-rails in case this is usable directly in the gem.

Contributor

eliotsykes commented Dec 13, 2014

Here's an initializer script that modifies the public Rails::Generators.hidden_namespaces config so the RSpec generators are no longer hidden when listing all available generators by running rails g.

https://github.com/eliotsykes/rspec-rails-examples/pull/11/files

I'll shortly take a go at submitting a pull request with a similar change to rspec-rails in case this is usable directly in the gem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment