Support for testing the compass command line when it expects stdin responses.
This commit is contained in:
parent
d5b711170c
commit
a9aa79d9a7
@ -2,6 +2,7 @@ require File.dirname(__FILE__)+'/test_helper'
|
|||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
require 'compass'
|
require 'compass'
|
||||||
require 'compass/exec'
|
require 'compass/exec'
|
||||||
|
require 'timeout'
|
||||||
|
|
||||||
class CommandLineTest < Test::Unit::TestCase
|
class CommandLineTest < Test::Unit::TestCase
|
||||||
include Compass::TestCaseHelper
|
include Compass::TestCaseHelper
|
||||||
@ -55,10 +56,49 @@ class CommandLineTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def compass(*arguments)
|
def compass(*arguments)
|
||||||
|
if block_given?
|
||||||
|
responder = Responder.new
|
||||||
|
yield responder
|
||||||
|
IO.popen("-", "w+") do |io|
|
||||||
|
if io
|
||||||
|
#parent process
|
||||||
|
output = ""
|
||||||
|
while !io.eof?
|
||||||
|
timeout(1) do
|
||||||
|
output << io.readpartial(512)
|
||||||
|
end
|
||||||
|
prompt = output.split("\n").last
|
||||||
|
if response = responder.response_for(prompt)
|
||||||
|
io.puts response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@last_result = output
|
||||||
|
else
|
||||||
|
#child process
|
||||||
|
execute *arguments
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
@last_result = capture_output do
|
@last_result = capture_output do
|
||||||
execute *arguments
|
execute *arguments
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Timeout::Error
|
||||||
|
fail "Read from child process timed out"
|
||||||
|
end
|
||||||
|
|
||||||
|
class Responder
|
||||||
|
def initialize
|
||||||
|
@responses = []
|
||||||
|
end
|
||||||
|
def respond_to(prompt, options = {})
|
||||||
|
@responses << [prompt, options[:with]]
|
||||||
|
end
|
||||||
|
def response_for(prompt)
|
||||||
|
pair = @responses.detect{|r| r.first == prompt}
|
||||||
|
pair.last if pair
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def assert_action_performed(action, path)
|
def assert_action_performed(action, path)
|
||||||
@last_result.split("\n").each do |line|
|
@last_result.split("\n").each do |line|
|
||||||
|
Loading…
Reference in New Issue
Block a user