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.
rails g rspec:model
The rails g rspec:install ran correctly, without any errors. In config/application.rb I have a following settings:
rails g rspec:install
config.generators do |gen|
gen.test_framework :rspec, :fixture => true, :views => false, :view_specs => false
gen.fixture_replacement :factory_girl, :dir => 'spec/factories'
This behaviour is noted in the documentation. The list of generators can be found in the lib/generators/rspec directory.
Hmm... well, I understand what motivated this decision. However, they should be listed on the help text of rspec:install . just for information.
Normally the generators are invoked alongside rails generate model, for instance. Do you have a good use case for invoking one outside that flow?
rails generate model
Yeah, if I write a model what is not an ActiveRecord::Base but an ActiveResource model. These models cannot generated via rails generate model.
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).
rails generate rspec:model
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.
@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.
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?
@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.
Yeah, it makes.
@hron84, are you interested in writing some docs?
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.
since I use rspec-rails everyday. PR on its way.
Improve generator documentation
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.
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.