Cucumber / Aruba Thor:在单个场景中测试多个命令,第一次通过,第二次失败

时间:2013-01-16 22:19:36

标签: ruby cucumber thor aruba

我正在尝试编写一个小型红宝石宝石,使用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文件存在,所以我无法弄清楚为什么它没有被正确模板化。

1 个答案:

答案 0 :(得分:0)

不幸的是,Aruba不支持:https://github.com/cucumber/aruba/issues/140

但是编写自己的步骤定义并不是很糟糕,只需要在传入的命令之前首先执行。请参阅https://github.com/cucumber/cucumber/wiki/Step-Definitions以获取示例。