【问题标题】:Cucumber errors suppressed (not displayed fully)抑制黄瓜错误(未完全显示)
【发布时间】:2010-07-12 22:41:45
【问题描述】:

我刚刚安装了黄瓜,我测试了它。我收到以下错误:

teefcomp:cucumber-intro teef$ cucumber features/manage_users.feature
Using the default profile...
F----F

Failing Scenarios:
cucumber features/manage_users.feature:6 # Scenario: User List

1 scenario (1 failed)
4 steps (4 skipped)
0m0.029s

它似乎在抑制错误。我期待的是这样的:

Feature: Manage users
  In order to understand my user base better
  As an administrator
  I want to view a list of users

  Scenario: User List
    Given I have users named George, Mary
      uninitialized constant User (NameError)
      ./features/step_definitions/user_steps.rb:3
      ./features/step_definitions/user_steps.rb:2:in '/^I have users named (.*)$/'
      features/manage_users.feature:7:in 'Given I have users named George, Mary'

有人知道如何让 cucumber 完整显示错误吗?

--backtrace--verbose-b--trace 不起作用;我仍然看到F----F 并列出了失败的场景,但我仍然希望在“NameError”行上有类似描述的内容。这是旧版黄瓜的功能吗? (我正在使用截屏视频开始使用黄瓜。)

【问题讨论】:

    标签: ruby-on-rails cucumber


    【解决方案1】:

    使用-b 标志运行应该会给你一个完整的回溯

    cucumber features/manage_users.feature -b
    

    编辑:

    此外,您可以使用--backtrace 的完整符号。如果您通过 rake 运行,请使用 --trace 标志运行

    要获得完整输出,您可以使用--format 标志。我通常使用--format pretty 来逐行浏览。

    来自--help 输出。

    -f, --format FORMAT              How to format features (Default: pretty). Available formats:
                                       debug       : For developing formatters - prints the calls made to the listeners.
                                       html        : Generates a nice looking HTML report.
                                       json        : Prints the feature as JSON
                                       json_pretty : Prints the feature as pretty JSON
                                       junit       : Generates a report similar to Ant+JUnit.
                                       pdf         : Generates a PDF report. You need to have the
                                                     prawn gem installed. Will pick up logo from
                                                     features/support/logo.png or
                                                     features/support/logo.jpg if present.
                                       pretty      : Prints the feature as is - in colours.
                                       progress    : Prints one character per scenario.
                                       rerun       : Prints failing files with line numbers.
                                       stepdefs    : Prints All step definitions with their locations. Same as
                                                     the usage formatter, except that steps are not printed.
                                       tag_cloud   : Prints a tag cloud of tag usage.
                                       usage       : Prints where step definitions are used.
                                                     The slowest step definitions (with duration) are
                                                     listed first. If --dry-run is used the duration
                                                     is not shown, and step definitions are sorted by
                                                     filename instead.
                                     Use --format rerun --out features.txt to write out failing
                                     features. You can rerun them with cucumber @rerun.txt.
                                     FORMAT can also be the fully qualified class name of
                                     your own custom formatter. If the class isn't loaded,
                                     Cucumber will attempt to require a file with a relative
                                     file name that is the underscore name of the class name.
                                     Example: --format Foo::BarZap -> Cucumber will look for
                                     foo/bar_zap.rb. You can place the file with this relative
                                     path underneath your features/support directory or anywhere
                                     on Ruby's LOAD_PATH, for example in a Ruby gem.
    

    【讨论】:

    • 试试--backtrace--verbose
    • 两者都给了我额外的信息,但是最有用的信息(“未初始化的常量用户(NameError)”行)仍然显示。
    • --backtrace 给了我这个:使用默认配置文件... F----F 失败场景:黄瓜 features/manage_users.feature:6 # 场景:用户列表 1 场景(1 失败) 4 步(跳过 4 步)0m0.026s
    • --verbose 给了我这个:使用默认配置文件... 代码:* features/support/env.rb * features/support/paths.rb 功能:* features/manage_users.feature 解析功能文件耗时 0m0.003s 代码:* features/step_definitions/user_steps.rb * features/step_definitions/web_steps.rb F----F 失败场景:黄瓜 features/manage_users.feature:6 # 场景:用户列表 1 场景(1 失败) 4 步(跳过 4 步)0m0.026s
    • 抱歉这些 cmets 没有格式化。我仍在尝试弄清楚如何做到这一点。
    【解决方案2】:

    如果您的应用程序是 Rails 应用程序,您可以将@allow-rescue 标签用于感兴趣的场景,那么您的 rails test_log 将包含有关应用程序中最初引发错误的位置的更多详细信息。

    在命令行中,您可以使用 tail -n200 log/test_log.rb 快速查看测试日志的结尾(调整行数以查看感兴趣的部分)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-17
      相关资源
      最近更新 更多