黄瓜 +阿鲁巴岛Windows:测试看不到标准输出的最后一行?

发布于 2024-11-04 03:20:54 字数 1330 浏览 1 评论 0原文

我正在 Windows 上的 Ruby 1.8.7 中使用 Cucumber 和 Aruba 运行基本的 BDD 演示。我们的想法是让一个简单的“问候语”应用程序提示用户输入姓名,然后通过姓名向他们打招呼。

Cucumber 场景如下所示:


# name_prompt.feature

Feature: Name prompt
    In order to interact with the bot
    As a friendly user
    I want to tell the app my name

    Scenario: Be asked
        Given the application is running
        Then I should see "What is your name?"

    Scenario: Talk back
        Given the application is running
        And I type "Tim" and press Enter
        Then I should see "Hello, Tim"

我的步骤实现使用了一些 Aruba 提供的函数,看起来像:


# cli_steps.rb

Given /^the application is running$/ do
  run_interactive(unescape("ruby chatbot.rb"))
end

Then /^I should see "([^"]*)"$/ do |arg1|
  assert_partial_output(arg1)
end

Given /^I type "([^"]*)" and press Enter$/ do |arg1|
  type(arg1)
end

机器人本身非常简单,看起来像:


# chatbot.rb
$stdout.sync = true

puts "What is your name?"
name = gets.chomp
puts "Hello, #{name}"

在 Mac/Linux 上,这工作正常并通过了所有场景。然而,在 Windows 上,我始终看到 assert_partial_output 中测试的输出不包含最后一行(“Hello, Tim”)。

我尝试在 @interactive.stdout 的内容上使用 pp,它应该包含程序的整个输出,但它只包含第一个“你叫什么名字” ?”行,加上换行符。

Windows 上是否存在任何问题会导致 Cucumber 和 Aruba 出现此类问题?为什么这些测试不能通过?

I'm running what should be a basic BDD demonstration using Cucumber and Aruba on Windows in Ruby 1.8.7. The idea is to have a simple "greeter" application prompt the user for a name, then say hello to them by name.

The Cucumber scenarios look like this:


# name_prompt.feature

Feature: Name prompt
    In order to interact with the bot
    As a friendly user
    I want to tell the app my name

    Scenario: Be asked
        Given the application is running
        Then I should see "What is your name?"

    Scenario: Talk back
        Given the application is running
        And I type "Tim" and press Enter
        Then I should see "Hello, Tim"

My step implementations use a few Aruba-provided functions, and looks like:


# cli_steps.rb

Given /^the application is running$/ do
  run_interactive(unescape("ruby chatbot.rb"))
end

Then /^I should see "([^"]*)"$/ do |arg1|
  assert_partial_output(arg1)
end

Given /^I type "([^"]*)" and press Enter$/ do |arg1|
  type(arg1)
end

The bot itself is pretty simple, and just looks like:


# chatbot.rb
$stdout.sync = true

puts "What is your name?"
name = gets.chomp
puts "Hello, #{name}"

On Mac/Linux, this works fine and passes all scenarios. On Windows, however, I'm consistently seeing that the output being tested in assert_partial_output doesn't include the last line (the "Hello, Tim").

I've tried using pp on the contents of @interactive.stdout, which should contain the entire output of the program, but it just contains the first "What is your name?" line, plus a line break.

Are there any issues on Windows that would cause this kind of trouble with Cucumber and Aruba? Why won't these tests pass?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

oО清风挽发oО 2024-11-11 03:20:54

似乎存在时间/缓冲问题。

我尝试过 ChildProcess(Aruba 在后台使用的库),与 Aruba 所做的唯一区别是在标准输入上调用 close 。即使没有 stdout 刷新,以下脚本也可与 Chartbot.rb 配合使用:

require "rubygems" unless defined?(Gem)
require "childprocess"
require "tempfile"

out = Tempfile.new "out"

process = ChildProcess.build("ruby", "chatbot.rb")
process.io.stdout = out
process.io.stderr = out
process.duplex = true

process.start
process.io.stdin.puts "Tim"
process.io.stdin.close

process.poll_for_exit 1
out.rewind
puts out.read

也许您可以向 Aruba 错误跟踪器报告此问题?

https://github.com/cucumber/aruba/issues

There seems to be a timing/buffer issue.

I've tried ChildProcess (the library that Aruba uses in the background) and the only difference with what Aruba does is invoke close on stdin. The following script works with chartbot.rb, even without stdout flush:

require "rubygems" unless defined?(Gem)
require "childprocess"
require "tempfile"

out = Tempfile.new "out"

process = ChildProcess.build("ruby", "chatbot.rb")
process.io.stdout = out
process.io.stderr = out
process.duplex = true

process.start
process.io.stdin.puts "Tim"
process.io.stdin.close

process.poll_for_exit 1
out.rewind
puts out.read

Perhaps you can report this issue to Aruba bug tracker?

https://github.com/cucumber/aruba/issues

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文