Skip to content

Commit

Permalink
add background runner step. last_stdout and last_stderr read from it'…
Browse files Browse the repository at this point in the history
…s streams if not set
  • Loading branch information
timcharper committed Sep 23, 2009
1 parent a82c5b0 commit 5905946
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
26 changes: 26 additions & 0 deletions features/steps/sandbox_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
run(localized_command(command, args))
end

When /^I run this in the background: (spork|spec|cucumber)(| .*)$/ do |command, args|
@background_script = run_in_background(localized_command(command, args))
end

When /^I fire up a spork instance with "spork(.*)"$/ do |spork_opts|
@spork_server = run_in_background("#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{SporkWorld::BINARY} #{spork_opts}")

Expand All @@ -56,6 +60,28 @@
end
end

Then /^the spork window should output a line containing "(.+)"/ do |expected|
output = ""
begin
status = Timeout::timeout(5) do
# Something that should be interrupted if it takes too much time...
while line = @spork_server.stdout.gets
output << line
puts line
break if output.include?(expected)
end
end
rescue Timeout::Error
output.should include(expected)
end
end

When /^I type this in the spork window: "(.+)"/ do |line|
@spork_server.stdin.puts(line)
@spork_server.stdin.flush
end


Then /^the file "([^\"]*)" should include "([^\"]*)"$/ do |filename, content|
in_current_dir do
File.read(filename).should include(content)
Expand Down
16 changes: 16 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ def initialize

private
attr_reader :last_exit_status, :last_stderr, :last_stdout, :background_jobs
def last_stderr
return @last_stderr if @last_stderr
if @background_job
@last_stderr = @background_job.stderr.read
end
end


def last_stdout
return @last_stdout if @last_stdout
if @background_job
@last_stdout = @background_job.stdout.read
end
end

def create_file(file_name, file_content)
file_content.gsub!("SPORK_LIB", "'#{spork_lib_dir}'") # Some files, such as Rakefiles need to use the lib dir
Expand Down Expand Up @@ -76,6 +90,8 @@ def terminate_background_jobs
background_job.kill
end
end
@background_jobs.clear
@background_job = nil
end

end
Expand Down

0 comments on commit 5905946

Please sign in to comment.