Michael Michael - 1 month ago 8
Ruby Question

Why does FakeFS break RSpec?

test_spec.rb: (from FakeFS example)

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 spec/test_spec.rb returns
superclass mismatch for class File
for the first test and normal
expected: 2 got: 1
in the second case. Matcher changing (e.g.
be_kind_of(String)
) does not affect the result. Why does this happen, and how can it be fixed?

ruby -v

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

Answer

Thanks @d.g for link to fakefs issue. Things that works:

Gemfile

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

spec/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
Comments