Skip to content

Instantly share code, notes, and snippets.

@dladowitz
Created June 28, 2012 00:15
Show Gist options
  • Save dladowitz/3007790 to your computer and use it in GitHub Desktop.
Save dladowitz/3007790 to your computer and use it in GitHub Desktop.
Rspec for Jesse's ToDo app
# require 'spec_helper'
require 'simplecov'
SimpleCov.start
require './list'
require './todo'
require './task'
describe Todo::List do
before :each do
@list = Todo::List.new('todo.txt')
end
# it "should have initialized properly" do
# @list.should be
# end
it "should add a task" do
@list.add_task("Clean the porch")
string_array = []
@list.task_strings { |string| string_array << string }
string_array.last.should match /Clean the porch/
@list.delete_task(string_array.length)
end
it "should delete a task" do
@list.add_task("123456789")
string_array = []
@list.task_strings { |string| string_array << string }
@list.delete_task(string_array.length)
string_array = []
@list.task_strings { |string| string_array << string }
string_array.last.should_not match /123456789/
end
it "should complete a task" do
@list.add_task("I want this to be completed")
string_array = []
@list.task_strings { |string| string_array << string }
@list.complete_task(string_array.length)
@list.print_tasks(:status => :complete)[-1].should be_complete
@list.delete_task(string_array.length)
end
it "should complete a task" do
@list.add_task("This should be incomplete")
string_array = []
@list.task_strings { |string| string_array << string }
@list.print_tasks(:status => :incomplete)[-1].should_not be_complete
@list.delete_task(string_array.length)
end
it "should parse text from a file into Task objects in an array" do
a = @list.parse_tasks("1. do laundry ; 2012-06-27 14:53:30 -0700 ; 2012-06-27 16:11:30 -0700\n2. eat food ; 2012-06-27 14:53:30 -0700 ; ")
a.should be_an_instance_of Array
a[0].should be_an_instance_of Todo::Task
a[0].to_s.should eq("do laundry ; 2012-06-27 14:53:30 -0700 ; 2012-06-27 16:11:30 -0700")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment