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