diff --git a/features/interactive.feature b/features/interactive.feature index 1ec6b3fb8..9cab7dc77 100644 --- a/features/interactive.feature +++ b/features/interactive.feature @@ -29,13 +29,11 @@ Feature: Interactive process control 7 """ - @wip - Scenario: Filesystem checks + Scenario: Stop processes before checking for filesystem changes See: http://github.com/aslakhellesoy/aruba/issues#issue/17 for context Given a directory named "rename_me" When I run "mv rename_me renamed" interactively - And sleep 1 Then the following directories should exist: | renamed | And the following directories should not exist: diff --git a/lib/aruba/api.rb b/lib/aruba/api.rb index b36f4efd5..14944d1e7 100644 --- a/lib/aruba/api.rb +++ b/lib/aruba/api.rb @@ -74,6 +74,8 @@ def check_exact_file_content(file, exact_content) end def check_directory_presence(paths, expect_presence) + stop_processes! + in_current_dir do paths.each do |path| if expect_presence @@ -143,37 +145,46 @@ def install_gems(gemfile) end end - def run_simple(cmd, fail_on_error=true) - @last_exit_status = run(cmd) do |process| - announce_or_puts(process.stdout) if @announce_stdout - announce_or_puts(process.stderr) if @announce_stderr - process.stop - end - - if(@last_exit_status != 0 && fail_on_error) - fail("Exit status was #{@last_exit_status}. Output:\n#{all_output}") - end + def processes + @processes ||= {} end - def run_interactive(cmd) - @interactive = run(cmd) + def stop_processes! + processes.each do |_, process| + process.stop + end end def run(cmd) cmd = detect_ruby(cmd) - @processes ||= {} in_current_dir do announce_or_puts("$ cd #{Dir.pwd}") if @announce_dir announce_or_puts("$ #{cmd}") if @announce_cmd - process = @processes[cmd] = Process.new(cmd) + process = processes[cmd] = Process.new(cmd) process.run! block_given? ? yield(process) : process end end + def run_simple(cmd, fail_on_error=true) + @last_exit_status = run(cmd) do |process| + announce_or_puts(process.stdout) if @announce_stdout + announce_or_puts(process.stderr) if @announce_stderr + process.stop + end + + if(@last_exit_status != 0 && fail_on_error) + fail("Exit status was #{@last_exit_status}. Output:\n#{all_output}") + end + end + + def run_interactive(cmd) + @interactive = run(cmd) + end + def write_interactive(input) @interactive.stdin.write(input) end