ruby-on-rails Rspec:nil.should_not be_nil在我预期失败的时候传递,为什么?

ct3nt3jp  于 4个月前  发布在  Ruby
关注(0)|答案(1)|浏览(61)

在Rails项目中做一些rspec工作。有点好奇为什么这些不应该是零期望通过。有什么想法吗?

it "nils should be nil" do
  @io = nil
  @io.should_not be_nil #passes (shouldn't!!)
  nil.should_not be_nil #passes (shouldn't!!)
  @io.should == nil # passes
  @io.should be_nil # passes
  @io.nil?.should be_true # passes
  #@io.nil?.should be_false # fails as expected
end

字符串

**更新:**基于这里的反馈,我已经能够隔离这一原因(这是从spec_helper中加载的东西).我相信这是由于.nil?.blank?的一个糟糕的搅拌,我将有一个与开发人员交谈,看看这些覆盖是否真的有必要在所有.

感谢那些帮助验证我的东西。

oxf4rvwz

oxf4rvwz1#

我不能复制你的陈述。我写了他们在一个假的规范在现有的项目这样。

require 'spec_helper'

describe "Pepper" do
  describe "simplicity" do
  before(:each) { @io = nil }
  # should fail
  it 'should be nil 1' do
    @io.should_not be_nil 
  end
  # should fail
  it 'should be nil 2' do
    nil.should_not be_nil 
  end
  # should NOT fail
  it 'should be nil 3' do
    @io.should == nil
  end
  # should NOT fail
  it 'should be nil 4' do   
    @io.should be_nil
  end
  # should NOT fail
  it 'should be nil 5' do
    @io.nil?.should be_true # passes
  end
  # should fail
  it 'should be nil 6' do
    @io.nil?.should be_false 
  end
  end
end

字符串
它返回-正如预期的-以下输出:

simplicity
should be nil 1 (FAILED - 1)
should be nil 2 (FAILED - 2)
should be nil 3
should be nil 4
should be nil 5
should be nil 6 (FAILED - 3)


所以也许你的spec_helper在暗示什么,这会激怒你的specs。

相关问题