diff --git a/lib/packages/cat.rb b/lib/packages/cat.rb index c25037e..77bd8b1 100755 --- a/lib/packages/cat.rb +++ b/lib/packages/cat.rb @@ -3,8 +3,10 @@ class Cat def self.main params # read the file whose name has been passed as the parameter, line-by-line - File.foreach(params[0]) do |line| - puts line + params.each do |p| + File.foreach(p) do |line| + puts line + end end rescue diff --git a/spec/packages/cat_spec.rb b/spec/packages/cat_spec.rb index 3aa5b9d..5d4f5ad 100755 --- a/spec/packages/cat_spec.rb +++ b/spec/packages/cat_spec.rb @@ -17,5 +17,15 @@ end end + context "given multiple existing files" do + it "prints the text in the file" do + File.write("first.txt", "Hello World!") + File.write("second.txt", "Goodbye World!") + expect(Cat.main("first.txt", "second.txt")).to eql(puts `cat first.txt second.txt`) + `rm first.txt` + `rm second.txt` + end + end + end end