rails plugin new <project_name> -T -d postgresql --dummy-path=spec/dummy --skip-turbolinks --skip-spring --mountable
-Tskips the creation of the test directory and the use ofTest::Unit--dummy-path=spec/dummysets up your dummy app in a spec directory--skip-turbolinks&--skip-springcreates a project that does not use turbolinks or spring--mountablecreates a "mountable" and namespace-isolated engine.
- In Gemfile:
gem 'rspec-rails'- user rspec in place of minitest (docs)gem 'capybara'- act as a user navigating your site in tests (docs)gem 'factory_girl_rails'- easily generate database objects without repetitive code in tests (docs)gem 'database_cleaner'- clean your database between tests (docs)
- In project_name.gemspec
- Change
s.homepage,s.summary, ands.descriptionto the correct info
- Bundle and install (
bundle execorrails g) where required, create additional required files
bundlerails g rspec:installmkdir spec/supporttouch spec/support/factory_girl.rbtouch spec/support/factories.rbtouch spec/support/database_cleaner.rb
- Add config data
-
In
spec/rails_helper.rbrequire 'capybara/rails'- Uncomment
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } - Change
config.use_transactional_fixtures = trueto... = false
- Uncomment
-
In
spec/support/factory_girl.rbRSpec.configure do |config| config.include FactoryGirl::Syntax::Methods end -
In
spec/support/factories.rbFactoryGirl.define do <factories for each model go here> end -
In
spec/support/database_cleaner.rbRSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) end config.before(:each) do DatabaseCleaner.strategy = :transaction end config.before(:each, :js => true) do DatabaseCleaner.strategy = :truncation end config.before(:each) do DatabaseCleaner.start end config.after(:each) do DatabaseCleaner.clean end # Optional for formatting output of test suite runs (see comments) config.formatter = :documentation end
- In lib/project_name/engine.rb:
config.generators do |g|
g.test_framework :rspec
g.fixture_replacement :factory_girl, :dir => 'spec/support/factories'
end