rubycucumberbddaruba

Cucumber + Aruba + Windows: Tests don't see last line of stdout?


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?


Solution

  • 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