-
-
Save dbc-challenges/2f6973cad74bd41fb86b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class List | |
attr_reader :title, :tasks | |
def initialize(title, tasks = []) | |
@title = title | |
@tasks = tasks | |
end | |
def add_task(task) | |
tasks << task | |
end | |
def complete_task(index) | |
tasks[index].complete! | |
end | |
def delete_task(index) | |
tasks.delete_at(index) | |
end | |
def completed_tasks | |
tasks.select { |task| task.complete? } | |
end | |
def incomplete_tasks | |
tasks.select { |task| !task.complete? } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rspec" | |
require_relative "list" | |
describe List do | |
# Your specs here | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Task | |
attr_reader :description | |
def initialize(description) | |
@description = description | |
@complete = false | |
end | |
def complete? | |
@complete | |
end | |
def complete! | |
@complete = true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rspec" | |
require_relative "task" | |
describe Task do | |
let(:description) { "Walk the giraffe" } | |
let(:task) { Task.new(description) } | |
describe "#initialize" do | |
it "takes a description for its first argument" do | |
Task.new("Feed the parakeet").should be_an_instance_of Task | |
end | |
it "requires one argument" do | |
expect { Task.new }.to raise_error(ArgumentError) | |
end | |
end | |
describe "#description" do | |
it "returns the correct description for the task" do | |
task.description.should eq description | |
end | |
end | |
describe "#complete?" do | |
it "returns false for incomplete tasks" do | |
task.complete?.should be_false | |
end | |
it "returns true for completed tasks" do | |
task.complete! | |
task.complete?.should be_true | |
end | |
end | |
describe "#complete!" do | |
it "changes the task from incomplete to completed" do | |
# | |
# Note the use of the `be_complete` method here. | |
# This is some RSpec goodness which expects a | |
# method `complete?` to be defined which returns | |
# true or false. | |
# | |
task.should_not be_complete | |
task.complete! | |
task.should be_complete | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment