2013-01-16 57 views
1

我正在嘗試使用Bundler和Thor編寫一個小的紅寶石創建一些模板。我正在黃瓜和阿魯巴寫測試,我無法讓他們通過。Cucumber/Aruba Thor:在單個場景中測試多個命令,第一次通過,第二次失敗

我在應用程序中定義的下列雷神CLI類:

require 'thor' 
require 'sleipnir' 
require 'sleipnir/generators/layout' 
require 'sleipnir/generators/app' 

module Sleipnir 
    class CLI < Thor 

    desc "app", "Generates an app directory and copies the appropriate files" 
    def app(app_name) 
     Sleipnir::Generators::App.start([app_name]) 
    end 

    desc "layout", "Generates specific layout based on template type" 
    def layout(template_type) 
     Sleipnir::Generators::Layout.start([template_type]) 
    end 
    end 
end 

這是app.rb文件:

require 'thor/group' 

module Sleipnir 
    module Generators 
    class App < Thor::Group 
     include Thor::Actions 

     argument :app_name, :type => :string 
     class_option :template_type, :default => :erb, :required => true 

     def self.source_root 
     File.dirname(__FILE__) 
     end 

     def create_app_dir 
     empty_directory(app_name) 
     end 

     def copy_app_scaffold 
     directory("app", app_name) 
     end 
    end 
    end 
end 

而且layout.rb文件:

require 'thor/group' 

module Sleipnir 
    module Generators 
    class Layout < Thor::Group 
     include Thor::Actions 

     class_option :template_type, :default => :erb, :required => true 

     def self.source_root 
     File.dirname(__FILE__) + "/template" 
     end 

     def copy_layout 
     template_type = options[:template_type] 
     template("layout_template.#{template_type}", "views/layout.#{template_type}") 
     end 
    end 
    end 
end 

我有爲app方法編寫的黃瓜測試,並通過秒。但是,layout方法失敗。下面是測試:

Feature: Generate 
    In order to generate templates 
    As a CLI 
    I want to run the generator 

    Scenario: Layout 
    When I run `sleipnir app test_app` 
    Then the following directories should exist: 
     | test_app/views | 
    When I run `sleipnir layout --template_type "erb"` 
    Then the following files should exist: 
     | test_app/views/layout.erb | 

測試的第一部分通過就好(即生成的目錄),但有關驗證該文件的部分存在失敗。我檢查了文件結構,並且存在layout_template.erb文件,所以我無法弄清楚它爲什麼不能正確模板化。

回答

相關問題