2

Ruby 1.8.7 の Windows で 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 では、これは正常に機能し、すべてのシナリオに合格します。assert_partial_outputただし、Windows では、テスト対象の出力に最後の行 ("Hello, Tim") が含まれていないことが常に見られます。

ppプログラムの出力全体を含むはずの の内容を使用してみまし@interactive.stdoutたが、最初の「あなたの名前は何ですか?」だけが含まれています。行に改行を加えます。

Cucumber と Aruba でこの種の問題を引き起こす Windows の問題はありますか? これらのテストに合格しないのはなぜですか?

4

1 に答える 1

2

タイミング/バッファの問題があるようです。

ChildProcess (Aruba がバックグラウンドで使用するライブラリ) を試しましたが、Aruba との唯一の違いはclosestdin での呼び出しです。次のスクリプトは、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

于 2011-04-28T23:29:14.317 に答える