Skip to content

Commit

Permalink
Reorder things a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Oct 18, 2011
1 parent 975a889 commit 4204ed9
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions tests.rb
@@ -1,3 +1,13 @@
# Task: Implement the rcat utility and get these tests to pass on a system
# which has the UNIX cat command present

# To see Gregory Brown's solution, see http://github.com/elm-city-craftworks/rcat
# Feel free to publicly share your own solutions

# If you want to see detailed commentary on how to solve this problem
# please subscribe to the Practicing Ruby Journal ( practicingruby.com )
# An article on this topic will be released on Tuesday 10/18.

require "open3"

working_dir = File.dirname(__FILE__)
Expand All @@ -13,6 +23,22 @@

############################################################################

cat_output = `cat #{gettysburg_file} #{spaced_file}`
rcat_output = `rcat #{gettysburg_file} #{spaced_file}`

fail "Failed 'cat [f1 f2] == rcat [f1 f2]'" unless cat_output == rcat_output

############################################################################

cat_output = `cat < #{spaced_file}`
rcat_output = `rcat < #{spaced_file}`

unless cat_output == rcat_output
fail "Failed 'cat < file == rcat < file"
end

############################################################################

cat_output = `cat -n #{gettysburg_file}`
rcat_output = `rcat -n #{gettysburg_file}`

Expand Down Expand Up @@ -55,13 +81,6 @@

############################################################################

cat_output = `cat #{gettysburg_file} #{spaced_file}`
rcat_output = `rcat #{gettysburg_file} #{spaced_file}`

fail "Failed 'cat [f1 f2] == rcat [f1 f2]'" unless cat_output == rcat_output

############################################################################

cat_output = `cat -ns #{gettysburg_file} #{spaced_file}`
rcat_output = `rcat -ns #{gettysburg_file} #{spaced_file}`

Expand All @@ -80,15 +99,6 @@

############################################################################

cat_output = `cat < #{spaced_file}`
rcat_output = `rcat < #{spaced_file}`

unless cat_output == rcat_output
fail "Failed 'cat < file == rcat < file"
end

############################################################################

`cat #{gettysburg_file}`
cat_success = $?

Expand All @@ -108,7 +118,6 @@
fail "Failed 'cat and rcat exit codes match on bad file"
end

# NOTE: rcat deviates slightly from cat in its output, but is still similar
unless rcat_err == "rcat: No such file or directory - some_invalid_file\n"
fail "Failed 'cat and rcat error messages match on bad file'"
end
Expand All @@ -123,7 +132,6 @@
fail "Failed 'cat and rcat exit codes match on bad switch"
end

# NOTE: rcat deviates slightly from cat in its output, but is still similar
unless rcat_err == "rcat: invalid option: -x\nusage: rcat [-bns] [file ...]\n"
fail "Failed 'rcat provides usage instructions when given invalid option"
end
Expand Down

0 comments on commit 4204ed9

Please sign in to comment.