Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Generators not listed only install #722

Closed
hron84 opened this Issue · 14 comments

6 participants

@hron84

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 behaviour is noted in the documentation. The list of generators can be found in the lib/generators/rspec directory.

@hron84

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

@alindeman
Collaborator

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

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
Owner

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

@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
Owner

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

@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
Owner
@hron84

Yeah, it makes.

@alindeman
Collaborator

@hron84, are you interested in writing some docs?

@hron84

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

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

@alindeman alindeman closed this issue from a commit
@fontno fontno Improve generator documentation
[Closes #749]
[Fixes #722]
db259d3
@alindeman alindeman closed this in db259d3
@eliotsykes

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
Something went wrong with that request. Please try again.