Test::Unit how to test file operations and file content
Asked Answered
M

1

0

I'm looking for a way to test methods that use File class with test_unit. It's really the same thing that issue with Rspec but how to make it work with test_unit.

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

What will the test be :

require 'test/unit'

def test_foo
...
end

Thanks for your help.

Musjid answered 23/7, 2012 at 20:18 Comment(0)
H
1

You can do the same thing the RSpec question landed on: have foo accept any IO object and use a StringIO in tests.

def foo(io)
  io.write("text")
end

Then

require "test/unit"

def test_foo
  testIO = StringIO.new
  foo testIO 
  assert_equal(testIO.string, "text")
end
Hereinbefore answered 23/7, 2012 at 22:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.