一Gemfile添加
group :development, :test do
gem 'rspec-rails', '~> 3.0.0'
gem 'factory_girl_rails'
gem 'guard-rspec', require: false
end
then bundle
二初始化Rspec
rails generate rspec:install
三利用factory_girl添加测试数据
新建目录factories,spec/factories, 所有的测试数据文件放在该目录下
FactoryGirl.define do
测试数据
end
四rspec guard added to Guardfile
guard init rspec
跑rspec注意:
1去掉一大推warning -> 在.rspec文件中去掉--warning
2如果不用ActiveRecord, you can remove this line.
#ActiveRecord::Migration.maintain_test_schema!