Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Require an index for remove

  • Loading branch information...
commit 5215e52796b6042daf040ab6a91c8b33ea3f67fc 1 parent eab9d83
@jdunphy authored
Showing with 12 additions and 2 deletions.
  1. +6 −2 lib/qer/todo.rb
  2. +6 −0 test/test_qer.rb
View
8 lib/qer/todo.rb
@@ -24,7 +24,11 @@ def add(item)
end
def remove(index)
- if item = self.queue.delete_at(index)
+ if index.nil?
+ print "Remove must have an index: ex. 'qer remove 3'"
+ return
+ end
+ if item = self.queue.delete_at(index.to_i)
self.history << [Time.now.to_s, item[0], item[1]]
write_history
write
@@ -171,7 +175,7 @@ def command(args)
when "add", "a"
self.add(args.join(" ")) # qer add Some task 1
when "remove", "r"
- self.remove(args.shift.to_i) # qer remove 0
+ self.remove(args.shift) # qer remove 0
when "push", "pu"
self.push(args.join(" ")) # qer push Some task 2
when "pop", "po"
View
6 test/test_qer.rb
@@ -195,6 +195,12 @@ def setup
assert_output "Provided index does not exist."
end
+ should "not remove anything with nil index" do
+ @todo.command(%w(remove))
+ assert_output /Remove must have an index:/
+ assert_equal 1, @todo.queue.size
+ end
+
should "push" do
@todo.command(%w(push some stuff))
assert_equal 2, @todo.queue.size
Please sign in to comment.
Something went wrong with that request. Please try again.