参考: http://www.webascender.com/Blog/ID/629/Testing-Rails-4-Apps-With-RSpec-3-Part-II
group :development, :test do gem 'rspec-rails', '~> 3.0.0' gem 'database_cleaner' end
bin/rails generate rspec:install
# spec/rails_helper.rb RSpec.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 end
# config/application.rb config.generators do |g| g.test_framework :rspec end
$ bin/rails generate rspec:model widget
$ rspec spec/models/pretty_day_spec.rb