【问题标题】:How can I test Cucumber user input and output with Highline?如何使用 Highline 测试 Cucumber 用户输入和输出?
【发布时间】:2014-07-06 10:29:19
【问题描述】:

我尝试了几种方法,例如存根 STDOUT、使用 highline-test 和 aruba gems,但它仍然会停止我的黄瓜测试并要求用户输入。是否有使用 Cucumber 测试此类应用程序的最佳实践?

【问题讨论】:

    标签: ruby testing cucumber highline


    【解决方案1】:

    Aruba 为我提供了解决方案。 首先,我的错误是创建应用程序根类的新实例而不检查if __FILE__ == $0

    最后看起来像这样:

    dashboard.feature:

    Feature: Manage app with dashboard
    As an app user
    In order to control application
    I want to have a dashboard
    
    Scenario: View dashboard
      When I run `../../lib/reporter.rb` interactively
      Then I should see following choices
        | 1 | Choice 1 |
        | 2 | Choice 2 |
        | 3 | Choice 3 |
    

    steps.rb:

    Then(/^I should see following choices$/) do |table|
      menu = ''
      table.rows_hash.each do |key, value|
        menu << "#{key}. #{value}\n"
      end
      Timeout::timeout(exit_timeout) do
        loop do
          break if assert_partial_output_interactive(menu)
          sleep 0.1
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2012-12-24
      • 1970-01-01
      • 2017-10-14
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多