使用黄瓜从功能文件获取标记 [英] Fetching tags from a feature file using cucumber

查看:293
本文介绍了使用黄瓜从功能文件获取标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有命令行选项来列出黄瓜测试套件中的所有标签?

Is there a command line option to list all the tags in your cucumber test suite?

例如,我想要的东西:
cucumber - -show-tags foo.feature

For example, I would want something like: cucumber --show-tags foo.feature

这会给我一些东西:

@ci
@development
@regression
@wip

我试过的语法是黄瓜-f tag_cloud foo.feature
,它给我不能加载tag_cloud(load_error)

The syntax which i have tried was "cucumber -f tag_cloud foo.feature" and its giving me "cannot load tag_cloud(load_error)"

我只是想知道如何做到这一点。

I just wanted to know how to do it exactly.

我需要安装任何API吗?还是怎么回事?

Do i need to install any api's additionally?? or how it is?

请帮我

推荐答案

我相信 - show-tags 选项已弃用。

Nat Ritmeyer对此任务有一个很好的自定义格式化程序 - https://gist.github.com/natritmeyer/2995205

Nat Ritmeyer had a good custom formatter for this task - https://gist.github.com/natritmeyer/2995205.

1)将以下内容复制到您的features / support目录中的list_tags.rb文件:

1) Copy the following into a "list_tags.rb" file in your "features/support" directory:

=begin

Copyright (c) 2012, Nathaniel Ritmeyer
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name Nathaniel Ritmeyer nor the names of contributors to
this software may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=end


require 'cucumber/formatter/console'
require 'cucumber/formatter/io'

module Cucumber
  module Formatter
    class ListTags
      include Io
      include Console

      def initialize(step_mother, path_or_io, options)
        @io = ensure_io(path_or_io, "list_tags")
        @all_tags = []
      end

      def tag_name(tag_name)
        @all_tags << tag_name
      end

      def after_features(features)
        @all_tags.uniq.sort.each {|tag| @io.puts tag}
      end
    end
  end
end

2)然后使用以下命令运行cucumber:

2) Then run cucumber using:

cucumber -d -f Cucumber::Formatter::ListTags

这样做(干)运行您的功能,并使用自定义格式化程序格式化结果。结果是一个标签列表。例如:

This does a (dry) run of your features and formats the results using the custom formatter. The results are a list of tags. For example:

@feature1
@feature2
@scenario1
@smoke1
@smoke2

这篇关于使用黄瓜从功能文件获取标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆