黄瓜 +阿鲁巴岛Windows:测试看不到标准输出的最后一行?
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎存在时间/缓冲问题。
我尝试过 ChildProcess(Aruba 在后台使用的库),与 Aruba 所做的唯一区别是在标准输入上调用
close
。即使没有 stdout 刷新,以下脚本也可与 Chartbot.rb 配合使用:也许您可以向 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:Perhaps you can report this issue to Aruba bug tracker?
https://github.com/cucumber/aruba/issues