首页 > 其他 > 详细

RSpec自定义matcher

时间:2016-03-03 20:48:35      阅读:184      评论:0      收藏:0      [点我收藏+]

链接 https://relishapp.com/rspec/rspec-expectations/v/3-4/docs/custom-matchers/define-a-custom-matcher#define-aliases-for-your-matcher

 

 1 require rspec/expectations
 2 class String
 3   def words
 4     split(‘‘)
 5   end
 6 end
 7 
 8 RSpec::Matchers.define :have_5_words do
 9   match do |thing|
10      thing.words.length == 5
11   end
12 end
13 
14 RSpec.describe String do
15   it { expect("hello").to have_5_words }
16 end

 

 

 

2.0版本 链接 https://relishapp.com/rspec/rspec-expectations/v/2-0/docs/matchers/have-n-items-matcher

 1 class String
 2   def words
 3     split( )
 4   end
 5 end
 6 
 7  describe String.new(hello) do
 8       it {
 9         should have(5).words }
10     end

 

RSpec自定义matcher

原文:http://www.cnblogs.com/or2-/p/5239721.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!