首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lettuce BDD:如何在step.behave_as中添加'Examples:‘块?

Lettuce BDD:如何在step.behave_as中添加'Examples:‘块?
EN

Stack Overflow用户
提问于 2014-09-15 15:56:43
回答 1查看 455关注 0票数 0

环境:Windows 8上的lettuce-0.2.23-py2.7

对于简单的场景(来自Lettuce文档的示例),一切正常:

代码语言:javascript
复制
@step('I am logged in')
def is_logged_in(step):
    step.behave_as("""
        Given I go to the home page
          And I click the login button
          And I fill in username:{user} password:{pass}
          And I click "Login"
    """.format(user='floppy', pass='banana'))

但是我不知道如何通过像这样的多个示例传递Scenario Outline

代码语言:javascript
复制
Given cat with name "<cat_name>"
Examples:
  |cat_name|
  |filemon |
  |tomcat  |

在父场景中粘贴:

代码语言:javascript
复制
@step('I have bunch of cats')
    def bunch_of_cats(step):
        step.behave_as("""
            Given cat with name "<cat_name>"
               Examples:
                |cat_name|
                |filemon |
                |tomcat  |
        """.format()

StackTrace:

代码语言:javascript
复制
Traceback (most recent call last):
  File "build\bdist.win-amd64\egg\lettuce\core.py", line 144, in __call__
    ret = self.function(self.step, *args, **kw)
  File "\\features\steps\manager_steps.py", line 590, in magic
    """.format())
  File "build\bdist.win-amd64\egg\lettuce\core.py", line 408, in behave_as
    assert not steps_undefined, "Undefined step: %s" % steps_undefined[0].sentence
AssertionError: Undefined step: Examples:

看起来我需要在实现behave_as方法来识别轮廓的lettuce-0.2.23-py2.7.egg!\lettuce\core.py中搞乱了。

另一种解决方案是使用examples作为集合来实现step的for loop。有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2014-12-09 17:24:22

当然,这里有一段代码:

代码语言:javascript
复制
@step("Given cat with name (\w+)")
def set_cat_name(step, name):
    step.behave_as("""
        Given another step that requires a name of a cat {0}
    """.format(name))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25843210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档