how to rspec generate in rails? i also install plugin for rspec.. i also install gem rspec,rspec-rails.. now what can i do??
Asked
Active
Viewed 9,945 times
9
-
1Also see http://stackoverflow.com/questions/9884033/ruby-on-rails-switch-from-test-unit-to-rspec to change your default generator forever. – Ghoti Jan 22 '13 at 13:41
4 Answers
23
Came here with the same question, and Don's answer got me on the right path. The generators however have : instead of _ in the name for Rails 3:
> rails g rspec:controller soa/user
create spec/controllers/soa/user_controller_spec.rb
> rails g rspec:scaffold soa/user
create spec/controllers/soa/users_controller_spec.rb
create spec/views/soa/users/edit.html.erb_spec.rb
create spec/views/soa/users/index.html.erb_spec.rb
create spec/views/soa/users/new.html.erb_spec.rb
create spec/views/soa/users/show.html.erb_spec.rb
invoke helper
create spec/helpers/soa/users_helper_spec.rb
create spec/routing/soa/users_routing_spec.rb
invoke rspec
create spec/requests/soa/soa_users_spec.rb
Annoyingly, these are not listed when you run rails g
but they are available.

asc99c
- 3,815
- 3
- 31
- 54
7
In your config/application.rb :
config.generators do |g|
g.test_framework :rspec
end

jjbohn
- 209
- 2
- 5
3
In config/application.rb, add this line of configuration code
config.generators do |g|
g.test_framework :rspec, :fixture => true, :views => false
g.integration_tool :rspec, :fixture => true, :views => true
end

Amrit Dhungana
- 4,371
- 5
- 31
- 36
1
Once you've installed rspec there will be new generators available called rspec_scaffold
, rspec_model
and rspec_controller
which work similarly to the normal rails generators except that instead of generating stub tests, they generate stub specs.

Michael Durrant
- 93,410
- 97
- 333
- 497

Don Roby
- 40,677
- 6
- 91
- 113