2011-04-28 46 views
2

我正在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上是否有任何问题会导致这种黄瓜和阿鲁巴的麻烦?为什么这些测试不会通过?

回答

2

似乎有一个时间/缓冲区问题。

我试过ChildProcess(Aruba在后台使用的库),唯一与Aruba不同的是在stdin上调用close。下面的脚本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 

也许你可以将此问题报告给阿鲁巴bug跟踪?

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

+0

这使我的答案:在Windows上,'@ process.io.stdin.sync'需要在子进程处理文件'process.rb'内设置为TRUE;。 – Tim 2011-05-03 02:11:48

相关问题