rspec be nil 和 be_nil 有什么区别 [英] rspec what is the difference between be nil and be_nil
本文介绍了rspec be nil 和 be_nil 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 rspec 和断言之类的
I am using rspec and for asserts like
student.name should be nil
student.name should be_nil
两者似乎都有效.使用 be nil
和 be_nil
有什么区别???
Both seem to work. is there a difference between using be nil
an be_nil
???
推荐答案
实际上没有区别,除了 be nil
被动态定义,而 be_nil
已经被定义由 rspec 专门编程.
There is no difference really, except be nil
gets defined on the fly, and be_nil
has been specifically programmed by rspec.
当你说should.be something
时,rspec会尝试以下
when you say should.be something
, rspec tries the following
[:==, :<, :<=, :>=, :>, :===].each do |operator|
define_method operator do |operand|
BeComparedTo.new(operand, operator)
end
end
然而,当你尝试 should.be_nil
时,它只是检查
Whereas, when you try should.be_nil
it just checks
object.nil?
https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/be.rb
这篇关于rspec be nil 和 be_nil 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文