2016-05-17 103 views
1

test_spec.rb:(从FakeFS example为什么FakeFS会破坏RSpec?

require 'fakefs/spec_helpers' 

describe 'Test' do 
    include FakeFS::SpecHelpers 
    it 'should fail' do 
    expect(1).to eq(2) 
    end 
end 

describe 'Test2' do 
    it 'should fail' do 
    expect(1).to eq(2) 
    end 
end 

rspec的规格/ test_spec.rb返回superclass mismatch for class File用于第一测试和正常expected: 2 got: 1在第二种情况下。匹配更改(例如be_kind_of(String))不会影响结果。为什么会发生这种情况?如何解决?

红宝石-v

ruby 2.4.0dev (2016-03-19 trunk 54188) [x86_64-linux] 
+1

见:https://github.com/fakefs/fakefs/issues/215 – lifetimes

回答

1

我只是有这个问题,而接受的答案并没有帮助我。

但我最终加入下面的一行到我spec_helper.rb顶部解决此问题:

require 'pp' 

我有一个.rspec文件与以下行,以确保spec_helper总是加载:

--require spec_helper 

在FakeFS自述文件中记录,您需要在fakefs之前需要pp以避免此问题,但我自己并不需要pp。它一定是我用*所暗示的其他宝石。

因此,通过在fakefs之前明确要求pp,我的规格现在按照他们的要求运行。

*我怀疑RSpec的使用pp的漂亮打印错误消息,因为我可能导致线路异常expect(true).to eq false

0

感谢@ d.g为link到fakefs问题。事情的工作:

的Gemfile

gem 'fakefs', require: 'fakefs/safe' 

规格/ spec_helper.rb

require 'fakefs/spec_helpers' 

RSpec.configure do |config| 
    config.include FakeFS::SpecHelpers, fakefs: true 
end 

test_spec.rb

require_relative 'spec_helper.rb' 

describe 'Test', fakefs: true do 
    it 'should fail' do 
    expect(1).to be_kind_of(String) 
    end 
end 
相关问题