我正在Ruby 1.8.7上运行Windows上使用Cucumber和Aruba的基本BDD演示。这个想法是让一个简单的“迎宾”应用程序提示用户输入一个名字,然后用名字向他们打招呼。Cucumber + Aruba + Windows:测试没有看到标准输出的最后一行?
黄瓜情景是这样的:
# 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"
我一步实现使用一些阿鲁巴提供的功能,看起来像:
# 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上是否有任何问题会导致这种黄瓜和阿鲁巴的麻烦?为什么这些测试不会通过?
这使我的答案:在Windows上,'@ process.io.stdin.sync'需要在子进程处理文件'process.rb'内设置为TRUE;。 – Tim 2011-05-03 02:11:48