Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete cat command #55

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/packages/cat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/packages/cat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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