diff --git a/aruba.gemspec b/aruba.gemspec index 8e3bfaf02..466bc80b5 100644 --- a/aruba.gemspec +++ b/aruba.gemspec @@ -16,6 +16,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'kramdown', '>= 0.14' s.add_development_dependency 'rake', '>= 0.9.2' s.add_development_dependency 'rspec', '>= 2.7.0' + s.add_development_dependency 'fuubar', '>= 1.1.1' s.rubygems_version = ">= 1.6.1" s.files = `git ls-files`.split("\n") diff --git a/features/interactive.feature b/features/interactive.feature index 511aef499..92d964244 100644 --- a/features/interactive.feature +++ b/features/interactive.feature @@ -31,6 +31,31 @@ Feature: Interactive process control Hello, world """ + @posix + Scenario: Pipe in a file + Given a file named "test.txt" with: + """ + line1 + line2 + """ + When I run `cat` interactively + And I pipe in the file "test.txt" + Then the output should contain: + """ + line1 + line2 + """ + + @posix + Scenario: Close stdin stream + When I run `cat` interactively + And I type "Hello, world" + And I close the stdin stream + Then the output should contain: + """ + Hello, world + """ + @posix Scenario: Stop processes before checking for filesystem changes See: http://github.com/aslakhellesoy/aruba/issues#issue/17 for context diff --git a/lib/aruba/api.rb b/lib/aruba/api.rb index 3826b123a..2d1f500d0 100644 --- a/lib/aruba/api.rb +++ b/lib/aruba/api.rb @@ -91,6 +91,14 @@ def check_file_presence(paths, expect_presence) end end + def pipe_in_file(file) + in_current_dir do + File.open(file, 'r').each_line do |line| + _write_interactive(line) + end + end + end + def check_file_size(paths_and_sizes) prep_for_fs_check do paths_and_sizes.each do |path, size| diff --git a/lib/aruba/cucumber.rb b/lib/aruba/cucumber.rb index 62ad72ca0..7a0ebe084 100644 --- a/lib/aruba/cucumber.rb +++ b/lib/aruba/cucumber.rb @@ -85,6 +85,16 @@ type(input) end +When /^I close the stdin stream$/ do + eot +end + +When /^I pipe in the file "([^"]*)"$/ do |file| + pipe_in_file(file) + + eot +end + When /^I wait for (?:output|stdout) to contain "([^"]*)"$/ do |expected| Timeout::timeout(exit_timeout) do loop do @@ -312,3 +322,4 @@ Then /^the file "([^"]*)" should not match \/([^\/]*)\/$/ do |file, partial_content| check_file_content(file, /#{partial_content}/, false) end + diff --git a/spec/aruba/api_spec.rb b/spec/aruba/api_spec.rb index 98fe31bdb..30ef21713 100644 --- a/spec/aruba/api_spec.rb +++ b/spec/aruba/api_spec.rb @@ -160,6 +160,13 @@ def announce_or_puts(*args) @aruba.eot @aruba.all_output.should == "Hello\n" end + + it "pipes data" do + @aruba.write_file(@file_name, "Hello\nWorld!") + @aruba.pipe_in_file(@file_name) + @aruba.eot + @aruba.all_output.should == "Hello\nWorld!" + end end end # Aruba::Api