RSpec: how to test file operations and file content

后端 未结 5 761
心在旅途
心在旅途 2020-12-24 00:40

In my app, I have the following code:

File.open "filename", "w" do |file|
  file.write("text")
end

I want to te

5条回答
  •  借酒劲吻你
    2020-12-24 01:38

    You can use fakefs.

    It stubs filesystem and creates files in memory

    You check with

    File.exists? "filename" 
    

    if file was created.

    You can also just read it with

    File.open 
    

    and run expectation on its contents.

提交回复
热议问题