Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Rails 3.1 with Rspec, Cucumber, Factory Girl, Haml, and Simple Form

Install Rails 3.1 RC

gem install rails --pre

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

# in Gemfile

gem 'haml'
gem 'haml-rails', :group => :development
gem 'simple_form'

group :test do
  gem 'database_cleaner'
  gem 'rails3-generators' #mainly for factory_girl & simple_form at this point
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'cucumber-rails'
  gem 'capybara'
  
end

Install our gems

bundle install

Configure generators to use the gems we want, and skip view spec generation

# in config/application.rb

config.generators do |g|
  g.test_framework :rspec, :views => false, :fixture => true
  g.fixture_replacement :factory_girl, :dir => 'spec/factories'
  g.form_builder :simple_form
  g.template_engine :haml
end

turn on autoloading of lib directory and all its subdirectories

In Rails 3+, the lib directory is no longer autoloaded.

# in config/application.rb
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]

run install tasks for our gems

rails g cucumber:install
rails g rspec:install
rails g simple_form:install
@tidelake

This comment has been minimized.

Show comment Hide comment
@tidelake

tidelake Jun 21, 2011

thank you. this is helpful

thank you. this is helpful

@olivierlacan

This comment has been minimized.

Show comment Hide comment
@olivierlacan

olivierlacan Aug 16, 2011

Can't that go in config/initializers/generators.rb ?
Thanks a lot for this.

Can't that go in config/initializers/generators.rb ?
Thanks a lot for this.

@endymion

This comment has been minimized.

Show comment Hide comment
@endymion

endymion Jan 28, 2012

Thanks!

Thanks!

@erlikh

This comment has been minimized.

Show comment Hide comment
@erlikh

erlikh Feb 5, 2012

thank you! meanwhile, config line for views specs should be:
g.test_framework :rspec, :view_specs => false, :fixture => true

erlikh commented Feb 5, 2012

thank you! meanwhile, config line for views specs should be:
g.test_framework :rspec, :view_specs => false, :fixture => true

@pramodshinde

This comment has been minimized.

Show comment Hide comment
@pramodshinde

pramodshinde Apr 5, 2013

why it is necessary to have hanl-rails ? only in development

why it is necessary to have hanl-rails ? only in development

@rodowi

This comment has been minimized.

Show comment Hide comment
@rodowi

rodowi Jun 10, 2013

I just had an issue where RSpec wouldn't find the action view templates written in haml.

I solved it by adding the haml-rails gem to the test group.

Thus, if you have the same issue I recommend:

group :development, :test do
  gem 'rspec-rails'
...
  gem 'haml-rails'
end

rodowi commented Jun 10, 2013

I just had an issue where RSpec wouldn't find the action view templates written in haml.

I solved it by adding the haml-rails gem to the test group.

Thus, if you have the same issue I recommend:

group :development, :test do
  gem 'rspec-rails'
...
  gem 'haml-rails'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment