test/rscm/command_line_test.rb in rscm-0.4.4 vs test/rscm/command_line_test.rb in rscm-0.4.5

- old
+ new

@@ -3,36 +3,39 @@ require 'rscm/command_line' module RSCM class DifftoolTest < Test::Unit::TestCase - def setup - @dir = RSCM.new_temp_dir("test_should_write_to_stdout") + def setup_dir(prefix) + @dir = RSCM.new_temp_dir(prefix) @stdout = "#{@dir}/stdout" @stderr = "#{@dir}/stderr" @prompt = "#{File.expand_path(@dir)} #{Platform.user}$" File.delete @stdout if File.exist? @stdout File.delete @stderr if File.exist? @stderr end def test_should_write_to_both_when_both_streams_specified_and_no_block + setup_dir(method_name) CommandLine.execute("echo \"<hello\" && echo world", {:dir => @dir, :stdout => @stdout, :stderr => @stderr}) - assert_equal("#{@prompt} echo \"<hello\"\n<hello\n#{@prompt} echo world\nworld\n", File.open(@stdout).read) - assert_equal("#{@prompt} echo \"<hello\"\n#{@prompt} echo world\n", File.open(@stderr).read) + assert_match(/.* echo \"<hello\"\s*\n.?\<hello.?\s*\n.* echo world\s*\nworld/n, File.open(@stdout).read) + assert_match(/.* echo \"<hello\"\s*\n.* echo world\s*/n, File.open(@stderr).read) end def test_should_not_write_to_stdout_when_no_stdout_specified + setup_dir(method_name) CommandLine.execute("echo hello", {:dir => @dir, :stderr => @stderr}) assert(!File.exist?(@stdout)) - assert_equal("#{@prompt} echo hello\n", File.open(@stderr).read) + assert_equal("#{@prompt} echo hello", File.open(@stderr).read.strip) end def test_should_only_write_command_to_stdout_when_block_specified + setup_dir(method_name) CommandLine.execute("echo hello", {:dir => @dir, :stdout => @stdout, :stderr => @stderr}) do |io| - assert_equal("hello\n", io.read) + assert_equal("hello", io.read.strip) end - assert_equal("#{@prompt} echo hello\n[output captured and therefore not logged]\n", File.open(@stdout).read) - assert_equal("#{@prompt} echo hello\n", File.open(@stderr).read) + assert_match(/.* echo hello\s*\[output captured and therefore not logged\]/n, File.open(@stdout).read.strip) + assert_equal("#{@prompt} echo hello", File.open(@stderr).read.strip) end end end \ No newline at end of file