Rails Test Setup Note

以下是一些关于测试的基本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/

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Awesome Ruby Toolbox Awesome A collection of awesome Ruby...
    debbbbie阅读 2,914评论 0 3
  • 这是一个简单的关于Rails Rspec的简单的介绍 1 安装Rspec 在Rails的配置文件Gemfile配置...
    AQ王浩阅读 27,070评论 6 28
  • 加速测试的方法 这里所说的“速度”有两层含义。 其一,当然是测试运行所用的时间。我们这个小程序的测试已经开始出现慢...
    AQ王浩阅读 2,567评论 1 9
  • 加速测试的方法 这里所说的“速度”有两层含义。 其一,当然是测试运行所用的时间。我们这个小程序的测试已经开始出现慢...
    AQ王浩阅读 967评论 0 1
  • 话说昨日,健哥让我分享下怎么用rspec写模型的测试,顿时一脸懵逼,因为只会些拳脚猫功夫,赶紧百度谷歌相关知识,七...
    严三金阅读 4,489评论 2 52