Skip to content

Instantly share code, notes, and snippets.

@pzaich
Created June 27, 2012 23:51
Show Gist options
  • Select an option

  • Save pzaich/3007689 to your computer and use it in GitHub Desktop.

Select an option

Save pzaich/3007689 to your computer and use it in GitHub Desktop.
require 'rspec'
require 'simplecov'
SimpleCov.start
require './list.rb'
require './task.rb'
#require './todo.rb'
describe Todo::Task do
before :all do
@new_task = Todo::Task.new("This is a task string")
end
it 'should be incomplete when it created' do
@new_task.incomplete?.should eq(true)
end
it 'should be able to for complete' do
@new_task.complete!
@new_task.complete?.should eq(true)
end
it 'it should accurately print out the date created and date completed' do
created_time = Time.now
completed_time = Time.now
@time_stamped_task = Todo::Task.new("I have opionions about when I was created", created_time, completed_time)
@time_stamped_task.to_s.should eq("I have opionions about when I was created ; #{created_time} ; #{completed_time}")
end
end
describe Todo::List do
item_text = "This is a new task"
before :all do
@new_list = Todo::List.new("todo.txt")
end
before :all do
@new_list.add_task(item_text)
end
it "will be initialized" do
@new_list.should be_an_instance_of Todo::List
end
it 'will print out each incomplete task' do
@new_list.print_tasks(:status => :incomplete).inspect.should include(item_text)
end
it 'will print out each complete task' do
@new_list.print_tasks(:status => :complete).should be_empty
end
it 'will print out all tasks' do
@new_list.print_tasks(:status => :some_other_value).inspect.should include(item_text)
end
it 'will can pass the block and print out the task in string' do
@new_list.task_strings(@tasks){|string| print string}.inspect.should include(item_text)
end
it 'can delete tasks from the list' do
@new_list.add_task("This is a 2nd task")
@new_list.delete_task(2)
@new_list.print_tasks(:status => :incomplete).inspect.should_not include("This is a 2nd task")
end
it "can complete a task item" do
@new_list.complete_task(1)
@new_list.print_tasks(:status => :complete).inspect.should include(item_text)
end
it "will clean the text file" do
@new_list.delete_task(1)
@new_list.print_tasks(:status => :some_other_value).should be_empty
end
it "will write task string to the file" do
@new_list.add_task("We use this string to test reading to the file")
returned_file_line = ""
File.open('todo.txt', 'r') do |file|
file.each do |line|
returned_file_line << line
end
end
returned_file_line.should include("We use this string to test reading to the file")
end
it "will clean the text file" do
@new_list.delete_task(1)
@new_list.print_tasks(:status => :some_other_value).should be_empty
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment