码迷,mamicode.com
首页 > 其他好文 > 详细

rspec subject{}和it{}

时间:2014-10-21 15:22:02      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   io   使用   sp   div   on   

subject { build(:user,firstname:john,lastname:doe)}
it { should be_named john doe}

it{}和subject{}互为别名

Gem扩展代码库 shoulda-matchers

直接使用

subject { Contact.new }
sperify { should validate_presence_of :firstname } 

自定义匹配器

Rspec::Matchers.define :be_named do |expected|
    match do |actual|
        actual.name eq expected
    end
    description do 
        "return a full name as a string"
    end
end

#use the defined matchers
it { should be_named John Doe}

 

rspec subject{}和it{}

标签:des   style   blog   color   io   使用   sp   div   on   

原文地址:http://www.cnblogs.com/xueyuwyz/p/4040224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!