我有以下雷神命令:測試互動雷神任務
require 'highline'
class Import < Thor
desc "files", "Import files into the database"
method_option "path", :required => true, :desc => "Path to folder containing new files", :aliases => "-p", :type => :string
def files
require './config/environment'
line = HighLine.new
line.say(line.color("Identified files as Version 15 (English)", :green))
if line.agree(line.color("Are you sure you want to import?", :yellow))
line.say(line.color("Finished. Imported 70,114 items", :green))
else
line.say(line.color("Aborting...", :red))
end
end
end
現在,很明顯,在目前這只是一些輸出語言到屏幕上。然而,我需要做的是爲測試輸出的命令編寫一個測試,就像我期望的那樣,並且當我開始沉迷於繁重的工作時,我可以將這些東西剔除。
我看了一下Aruba,但這似乎並不喜歡某些原因互動性,目前還不清楚這是爲什麼。
因此,有沒有人有任何想法如何可以測試(與RSpec)?
我想你也可以要求「阿魯巴/ API」與使用的方法是實現有 https://github.com/cucumber/寫方案aruba/blob/master/lib/aruba/api.rb 即使在RSpec中 – timsly
這會不會失敗,因爲tmp/aruba中沒有任務導入? – Ziggy
尼爾·米德爾頓寫的Thor腳本不會失敗,因爲它只寫入輸出。所以如果我輸入yes,它會返回我所期望的。 但是,當我們將有一些文件操作代碼,我們可以使用相對路徑,一切都應該工作 – timsly