Rails Test Setup Note

1458 ワード

以下はいくつかのテストに関する基本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には、RSpecにrequire 'factory_girl_rails' 3.2を加える.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/を加える