如何在rspec中模拟目录的创建?

时间:2016-09-28 09:52:33

标签: ruby rspec

这是创建目录的方法。

rspec

我为此方法创建了fakefs,并使用it 'should create directory given path as parameter' do FakeFS do create_directory(DIRECTORY_PATH) end expect(File.exists?(DIRECTORY_PATH)).to be_truthy end 来模拟目录的创建。

rspec

执行 Failures: 1) common Test for common method use should create file given file as parameter Failure/Error: expect(File.exists?(DIRECTORY_PATH)).to be_truthy expected: truthy value got: false # ./spec/unit/lib/common_spec.rb:16:in `block (3 levels) in <top (required)>' Finished in 0.01474 seconds (files took 0.10763 seconds to load) 2 examples, 1 failure Failed examples: rspec ./spec/unit/lib/common_spec.rb:12 # common Test for common method use should create file given file as parameter 命令时,出现此错误。

{{1}}

如何使用rspec或fakefs模拟目录的创建?

1 个答案:

答案 0 :(得分:3)

  1. 使用ruby tools创建目录而不是外壳。
  2. 将您的期望转移到fakefs块。