2012-06-07 16 views
1

我有以下雷神命令:測試互動雷神任務

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)?

回答

0

這裏是你如何能與Aruba做到這一點

Scenario: Test import 
    When I run `thor import` interactively 
    And I type "yes" 
    Then the stdout should contain "Finished. Imported 70,114 items" 

在這裏,你可以找到很多的阿魯巴例子 https://github.com/cucumber/aruba/blob/master/features/interactive.feature

這裏是實現自身 https://github.com/cucumber/aruba/blob/master/lib/aruba/cucumber.rb

+0

我想你也可以要求「阿魯巴/ API」與使用的方法是實現有 https://github.com/cucumber/寫方案aruba/blob/master/lib/aruba/api.rb 即使在RSpec中 – timsly

+0

這會不會失敗,因爲tmp/aruba中沒有任務導入? – Ziggy

+0

尼爾·米德爾頓寫的Thor腳本不會失敗,因爲它只寫入輸出。所以如果我輸入yes,它會返回我所期望的。 但是,當我們將有一些文件操作代碼,我們可以使用相對路徑,一切都應該工作 – timsly

3

阿魯巴是一個漂亮的測試命令行應用程序的完整步驟。如果它不適合你,可能是因爲aruba將所有文件操作默認爲tmp/aruba

但neimOo是正確的關於如何與Aruba

When I run `thor import` interactively 
And I type "yes"