我正在使用 rspec 并用于断言
student.name should be nil
student.name should be_nil
两者似乎都有效。be nil
使用be_nil
???有区别吗?
我正在使用 rspec 并用于断言
student.name should be nil
student.name should be_nil
两者似乎都有效。be nil
使用be_nil
???有区别吗?
真的没有什么区别,除了be nil
动态定义,并且be_nil
由 rspec 专门编程。
当你说should.be something
rspec 尝试以下
[:==, :<, :<=, :>=, :>, :===].each do |operator|
define_method operator do |operand|
BeComparedTo.new(operand, operator)
end
end
然而,当您尝试时,should.be_nil
它只是检查
object.nil?
https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/be.rb
我认为没有区别,但它用于与其他方法(如be_true
or )保持一致be_false
。
在引擎盖下be
检查id
两个元素:
与nil
失败,true
因为在 Ruby 中,一切都不是,false
也不nil
是true
失败,false
因为两者nil
都false
匹配