2014-07-06 89 views
1

我正在使用Thor編寫CLI。它看起來像這樣:測試Thor CLI

module Cli 
    class Root < Thor 
    register Cli::Command :command, 'command [ARGUMENT]', 'description' 
    end 
end 

module Cli 
    class Command < Thor::Group 
    include Thor::Actions 

    argument :argument 

    def template 
     directory :template_dir, argument 
    end 
    end 
end 

現在我想測試這個。也就是說,我想測試模板是在給定相對路徑和絕對路徑的正確目錄下創建的。然而,我對如何去測試這個有點失望。任何幫助將不勝感激。

回答

0

爲了測試Thor::Group,你可以做到以下幾點:

# my_spec.rb 
describe Cli::Command do 
    it 'should run the command' do 
    Cli::Command.new.invoke_all 
    end 
end