Mari
Mari

Reputation: 33

Spec for method

I have this method in my class

def open
  File.open(@filepath,"w") do |f|
    @gz = Zlib::GzipWriter.new(f)
    @gz.write(%[<?xml version="1.0" encoding="UTF-8"?>\n])
    @gz.write(%[<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n])
    yield self
    @gz.write(%[</urlset>])
    @gz.close
  end
end

How can I write a good complete spec for this method.

Thanks in advance

Upvotes: 1

Views: 63

Answers (2)

megas
megas

Reputation: 21791

You can use fakefs to interact with file system

Upvotes: 1

Reactormonk
Reactormonk

Reputation: 21690

Create a temporary filename, use that as @filepath, write some data, read the data back via File.read(filename), unzip it, compare.

Upvotes: 0

Related Questions