Skip to content

Instantly share code, notes, and snippets.

@perspectivezoom
Created June 27, 2012 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perspectivezoom/3007648 to your computer and use it in GitHub Desktop.
Save perspectivezoom/3007648 to your computer and use it in GitHub Desktop.
require 'rspec'
require 'simplecov'
SimpleCov.start
require './task.rb'
describe Todo::Task do
before(:each) do
@time = Time.now
Time.stub(:now).and_return(@time)
@task = Todo::Task.new("bake a cake")
end
subject { @task }
describe '#initialize' do
it 'should create a Task instance' do
should be_an_instance_of Todo::Task
end
end
describe '::from_string' do
it "should exist" do
Todo::Task.should respond_to :from_string
end
it "should create a Task if given a string" do
task = Todo::Task.from_string("2. eat food ; 2012-06-27 11:51:49 -0700 ; 2012-06-27 11:51:49 -0700")
task.should be_an_instance_of Todo::Task
end
end
[:to_s, :complete!, :complete?, :incomplete?].each do |attribute|
it { should respond_to attribute }
end
describe '#to_s' do
it "should write a string representing the task" do
@task.to_s.should eq "bake a cake ; #{@time} ; "
end
it "should write a string representing the task for completed tasks" do
@task.complete!
@task.to_s.should eq "bake a cake ; #{@time} ; #{@time}"
end
end
describe '#incomplete?' do
it "should return true if task is incomplete" do
@task.incomplete?.should eq true
end
it "should return false if task is complete" do
@task.complete!
@task.incomplete?.should eq false
end
end
describe '#complete?' do
it "should return false if task is incomplete" do
@task.complete?.should eq false
end
it "should return true if task is complete" do
@task.complete!
@task.complete?.should eq true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment