您的位置:首页 > 编程语言 > Ruby

说说rspec测试的使用

2013-08-23 00:37 357 查看
近来开始学习ruby on rails,用rspec做unit test.

An basic rspec testing requires the following steps:

1. add gem 'rspec-rails' to Gemfile and run 'bundle install'

2. run
'rails generate rspec:install
' to initialize rspec and generate spec directory. Two configuration files will be added under spec/: .rspec and spec_helper. spec_helper defines configurations required to run the test. Some more can be added
here, for example, vcr configuration. .rspec file can define how the result will be shown. You can run 'rspec --help' for more information.

3. Add a test. File name usually is class_name_spec.rb. A template can be as follows:

require 'spec_helper'
describe className do
context '...' do #optional
it "should..." do
sth.should == expected
end
end
end

4. run the test
rspec file_directory

That's all.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ruby 测试 rspec