以下是一些关于测试的基本gem的引入和初始化,方便以后copy&past。
1. 引入gem
# rspec-rails is a testing framework for Rails 3.x and 4.x.
# https://github.com/rspec/rspec-rails
gem 'rspec-rails', '~> 3.2.1'
# Collection of testing matchers extracted from Shoulda
# http://matchers.shoulda.io
gem 'shoulda-matchers', :require => false
# A library for setting up Ruby objects as test data
# https://github.com/thoughtbot/factory_girl
gem 'factory_girl_rails', '~> 4.4.1'
# Code coverage for Ruby 1.9+ with a powerful configuration library and automatic merging of coverage across test suites
# https://github.com/colszowka/simplecov
gem 'simplecov', '~> 0.7.1'
执行 bundle
.
2. rSpec setup
2.1 执行 rails generate rspec:install
2.2 忽略 rspec
3. factory_girl setup
3.1 在spec/spec_helper.rb内加入
require 'factory_girl_rails'
3.2 在RSpec.configure do |config|后面加入
config.include FactoryGirl::Syntax::Methods
4. Shoulda matchers setup for rSpec
在spec/rails_helper.rb内加入
require 'shoulda/matchers'
5. simpleCov Setup
5.1 在spec/spec_helper.rb内插入
if ENV["sc"]
require 'simplecov'
SimpleCov.start 'rails'
end
5.2 忽略simpleCov coverage report directory
在ignore内加入
coverage/