Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions terminator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,31 @@
subject.protect_sarah_connor!
subject.current_mission.should eq("protect: sarah_connor")
end

describe "#protects?" do
it "should return true when protecting Sarah Connor" do
subject.protect_sarah_connor!
subject.protects?(:sarah_connor).should be_true
end
it "should return false when destroying Sarah Connor" do
subject.destroy_sarah_connor!
subject.protects?(:sarah_connor).should be_false
end
it "should protect Sarah and John Connor at the same time" do
subject.protect_sarah_connor!
subject.protect_john_connor!
subject.protects?(:sarah_connor).should be_true
end
end

describe "#good?" do
it "should return true if the terminator is good" do
subject.protect_sarah_connor!
subject.good?.should be_true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with RSpec you could also

subject.should be_good

end
it "should return false if the terminator is bad" do
subject.destroy_john_connor!
subject.good?.should be_false
end
end
end
9 changes: 9 additions & 0 deletions terminatorable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ def likes_to_protect(people=[])
["destroy", "protect"].each do |mission_type|
people.each do |person|
define_method "#{mission_type}_#{person}!" do
@protected_person ||= []
@current_mission = "#{mission_type}: #{person}"
@protected_person << person if mission_type == "protect"
@mission_type = mission_type
end
end
end
Expand All @@ -15,5 +18,11 @@ def likes_to_protect(people=[])
def self.included(klass)
attr_reader :current_mission
klass.extend Terminatorable::ClassMethods
def protects?(person)
@protected_person.include? person
end
def good?
@mission_type == "protect"
end
end
end