[英]Testing interactive thor tasks
我有以下thor命令:
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)有任何想法?
Aruba是一套完整的測試命令行應用程序的步驟。 如果它不適合你,可能是因為aruba將所有文件操作默認為tmp/aruba
。
但是neimOo對於如何使用aruba編寫場景是正確的
When I run `thor import` interactively
And I type "yes"
以下是使用Aruba執行此操作的方法
Scenario: Test import
When I run `thor import` interactively
And I type "yes"
Then the stdout should contain "Finished. Imported 70,114 items"
在這里你可以找到很多aruba示例https://github.com/cucumber/aruba/blob/master/features/interactive.feature
這里是實現本身https://github.com/cucumber/aruba/blob/master/lib/aruba/cucumber.rb
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.