0
我有一個文本文件,我打算將其轉換爲CSV(本例中)格式。如何創建適當的RSpec測試以查看輸出是否適合以下場景的格式?爲文件輸入創建一個Ruby RSpec測試用例
這是我的代碼:
class ProcessLog
@@log = Array.new
def read_log(log)
if File.exists?(log)
f = File.open(log, "r")
f.each_line { |line| @@log << line.strip }
end
end
def process_log
result = Array.new
@@log.each do |line|
<convert to csv>
result << <converted to csv>
end
result
end
end
describe ProcessLog do
before do
@pl = ProcessLog.new
<help>
end
it 'should pass first format' do
text = "Item X has a price of $ per gram" # just as an example
<help>
@pl.read_log("file.log")
@pl.should == 'X,$,gram'
end
end
非常類似於我以前的版本。 但後來,我最終添加了幾個方法,需要日誌,我想刪除將日誌作爲參數傳遞給所有方法的依賴性。 : - \ – 2010-07-30 15:26:06